【发布时间】:2014-09-23 07:46:02
【问题描述】:
我有一个正在运行的线程应用程序正在计算一些更长的计算。
procedure TForm.calculationInThread(value: Integer);
var aThread : TThread;
begin
aThread :=
TThread.CreateAnonymousThread(
procedure
begin
myCalculation(value);
end
);
aThread.FreeOnTerminate := True;
aThread.OnTerminate := self.calculationInThreadEnd;
aThread.Start;
end;
还有一个calculationInThreadEnd的实现;
procedure TForm.calculationInThreadEnd(Sender: TObject);
begin
doSomething;
end;
我可能会错过一些愚蠢的东西,但是如何将值传递给calculationInThreadEnd?我找到了
TThread.SetReturnValue(value);
但我如何在 onTerminate 调用中访问它?
解决方案
type THackThread = class(TThread);
procedure TForm1.calculationInThreadEnd(Sender: TObject);
var Value: Integer;
begin
Value := THackThread(Sender as TThread).ReturnValue;
end;
【问题讨论】:
标签: multithreading delphi delphi-xe2