这个简单的示例在双击 Button1 时引发异常(无效参数)。
您可能需要多次单击才能收到消息。
这段代码有什么问题?
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
TTestThread = class(TThread)
protected
procedure Execute; override;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var MyThread : TTestThread;
begin
MyThread:=TTestThread.Create(true);
MyThread.FreeOnTerminate:=True;
MyThread.Priority:=tpHighest;
MyThread.Resume;
end;
{ TTestThread }
procedure TTestThread.Execute;
var len : integer;
begin
len := Form2.Canvas.TextWidth('test');
if (len=0) then
Raise Exception.Create(SysErrorMessage(GetLastError));
end;
end.