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.
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal