lazarus 執行緒1

老夫子的PASCAL發表於2024-07-11

標準執行緒用法
Type
TAnalyzedataThread = class(TThread)
private
procedure DoProcedure;
protected
procedure Execute; override;
public
Constructor Create(CreateSuspended : boolean);
end;

constructor TAnalyzedataThread.Create(CreateSuspended : boolean);
begin
FreeOnTerminate := True;
inherited Create(CreateSuspended);
end;

procedure TAnalyzedataThread.DoProcedure;
begin
//Memo1.Lines.Add(IntToStr(SRList.Count));
Terminate();
end;

procedure TAnalyzedataThread.Execute;
begin
while (not Terminated) do
begin
Synchronize(@DoProcedure);
end;
end;

var
AnalyzedataThread:TAnalyzedataThread; //分析資料執行緒,一直在跑

呼叫方法
AnalyzedataThread:=TAnalyzedataThread.Create(True);
AnalyzedataThread.Resume;

匿名執行緒
TThread.CreateAnonymousThread(@ReceiveThread).Start;

加入windows後,所有執行緒用法也DELPHI一致

相關文章