[Lazarus] Help: Multithreading

Mattias Gaertner nc-gaertnma at netcologne.de
Wed Aug 15 18:09:42 CEST 2012



Clinton Shane Wright <clintonabco at gmail.com> hat am 15. August 2012 um 17:20
geschrieben:

> Hi everyone,
> 
>  I hope that someone can help me understand a little bit better on how to work
> with threads in Lazarus. I am still learning so please forgive my ignorance in
> any matter here. I am using the multithreading.lpi example supplied with
> lazarus and I create a type TMyThread of class TThread and I have the Execute
> and other procedures made for the TMyThread thread. I have got the thread
> running well, but now I dont understand how to make another instance of the
> same thread and how write my code to identify which instance is running so
> that I can assign different tasks to each thread individually.
> 
>  On Form Create Procedure I have (as in the mulithreading example), MyThread
> := TMyThread.Create(False); This creates and instance of the type TMyThread. I
> got that. I got that working. Now with the same procedures if I go ahead and
> create another instance in the On Form  Create Procedure, MyThread2 :=
> TMyThread.Create(False); How do I use this second instance to do different
> work in the same procedures. I hope that whoever reads this can get what I am
> saying. I will post a link to the code below and I hope that someone can
> advise me. Any help is much appreciated.
> 
You can set variables of MyThread2 before starting it:

MyThread2 := TMyThread.Create(True);
MyThread2.Flag := 2;
MyThread2.Start;


> 
>     If I may add, I am using the thread to read data from a modem from the
> RS232, but now I have more than one modem connected to the system that I need
> to read from at once and having it run in one thread gets slower as I add one
> modem extra to the thread, I want to use the second instance, TMyThread2 to
> control the modem 2.
> 
>     http://www.heypasteit.com/clip/0FVU <http://www.heypasteit.com/clip/0FVU>
> 
>     Please I am desperate to know how to use this correctly.
> 

Mattias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20120815/c01fdd81/attachment-0003.html>


More information about the Lazarus mailing list