|
|
|
Using threads Part II. TThread class.
The VCL includes TThread class - an abstract class that enables creation of separate threads of execution in an application. Now let's look at TThread closely. Creating a descendant of TThread.TThread is an abstract class that means that you can't use TThread class itself. You need to create a subclass, which overrides Execute method at least. Each new instance of a subclass object is a new thread of execution. Multiple instances of a TThread derived class make a Delphi application multi-threaded. Delphi documentation notes: "the recommended limit is 16 threads per process on single processor systems". TThread virtual and protected methods.A protected member is visible anywhere in the module where its class is declared and from any descendant class, regardless of the module where the descendant class appears. Protected members are intended for use only in the implementation of derived classes. A virtual method can be redefined in descendant classes, but still be called in the ancestor class. The address of a virtual method isn't determined at compile time; instead, the object where the method is defined looks up the address at runtime. Execute method.Execute method is an abstract method that contains
the code which executes when the thread is run. DoTerminate method.Current implementation of DoTerminate method
generates an OnTerminate event in the context of main
VCL thread using Synchronize. Terminated property.Indicates that the thread has been asked to terminate. The Terminate method sets the Terminated property to True. The thread's Execute method and any methods that Execute calls should check Terminated periodically and exit when it's True. Program example.type Code explanation.It's very simple program. Source code contains two classes: TForm1 class.TForm1 class inherited from TForm represents the main application form that owns Memo, two buttons and spin-edit controls. In addition, there are some event handlers. Procedure btnCreateClick() is called when user clicks Go To Page: 1 2
The copyright of the article Using threads Part II. TThread class. in Delphi Programming is owned by . Permission to republish Using threads Part II. TThread class. in print or online must be granted by the author in writing.
|
|
|
|
|
|
|
|