我需要Thread独立工作Form.例如,我的循环无限Thread:
procedure TCustomThread.doProc;
begin
repeat
.
.
.
until (1 = 2);
end;
procedure TCustomThread.Execute;
begin
inherited;
Synchronize(doProc);
end;
.
.
.
procedure TForm1.Button1Click(Sender: TObject);
var
thrd : TCustomThread;
begin
thrd := TCustomThread.Create(True);
thrd.Resume;
Application.ProcessMessages;
end;
Run Code Online (Sandbox Code Playgroud)
现在,当我点击时Button1,我的Thread跑步但主要Form是锁定.我怎样才能避免暂停Form?
我有一个项目,主要Form是在我之后创建的Thread.但是这段代码无法正常工作:
type
TMyThread = class(TThread)
public
procedure Execute; override;
procedure doProc;
end; { type }
.
.
.
procedure TForm1.FormCreate(Sender: TObject);
var
thrd : TMyThread;
begin
thrd := TMyThread.Create(True);
thrd.Resume;
// Following code will cause the `Form` to show the time delay is about 5 seconds...
end;
.
.
.
procedure TMyThread.Execute;
begin
inherited;
doProc;
end;
procedure TMyThread.doProc;
var
AForm : TForm;
begin
AForm := TForm.Create(nil);
AForm.Caption := 'Thread Form';
AForm.Position := poScreenCenter;
AForm.FormStyle := fsStayOnTop; …Run Code Online (Sandbox Code Playgroud)