[fpc-pascal] changes in TThread.OnTerminate in fcp-3.0?
Anthony Walter
sysrpl at gmail.com
Thu Dec 10 14:13:28 CET 2015
I use a four method pattern with threads, while reusing the same thread
class everywhere.
1) define a status method to update your user interface based on feedback
from the thread
2) define a terminate method to do clean up when a thread finishes
3) define a work method where the thread does its execution
4) define a method which starts the thread feeding it all three methods
above
procedure TReplaceForm.ThreadStatus(Sender: TObject);
begin
Caption := FThread.Status;
end;
procedure TReplaceForm.ThreadTerminate(Sender: TObject);
begin
FThread := nil;
end;
procedure TReplaceForm.ThreadExecute(Thread: TSimpleThread);
begin
Thread.Status := 'Step 1';
Sleep(1000);
Thread.Status := 'Step 2';
Sleep(1000);
end;
procedure TReplaceForm.ReplaceButtonClick(Sender: TObject);
begin
if FThread = nil then
FThread := TSimpleThread.Create(ThreadExecute, ThreadStatus,
ThreadTerminate);
end;
And done. You never have to define your own TThread derived class again.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20151210/20937cf4/attachment.html>
More information about the fpc-pascal
mailing list