[Lazarus] Multiple Threads created from the same TThread object

Michael Schnell mschnell at lumino.de
Mon Jun 27 11:23:39 CEST 2011


On 06/27/2011 06:38 AM, Malcom Haak wrote:
>
> My issue is it seems that the First instance of this thread works 
> where as all instances after the first do not appear to work correctly.
> The method only uses variables that are local to the method, and all 
> other variables are actually added to the Thread class. So they should 
> be created new each time a new thread is created.
It should be no problem to instantiate the same TThread sibling multiple 
times (e.g. using myThread[i] := TmyThread.Create() ). In most projects 
the instance needs to know which one it is, so it might be sensible to 
have a property TmyThread.Instance and assign the instance number before 
the thread runs (or e.g. use Tag):

myThread[i] := TmyThread.Create(True);
myThread[i].Tag := i;
myThread.Suspended := False;

(or similar)

-Michael




More information about the Lazarus mailing list