Assigning Separate Names to Similar Threads
Go Up to Naming a Thread
All thread instances from the same thread class have the same name. However, you can assign a different name for each thread instance at run time using the following steps.
To assign separate names to similar threads
-
Add a ThreadName property to the thread class by adding the following in the class definition:
property ThreadName: string read FName write FName; __property AnsiString ThreadName = {read=FName, write=FName};
__property AnsiString ThreadName = {read = FName, write = FName};
-
In the SetName method, change where it says:
ThreadNameInfo.FName := 'MyThreadName'; info.szName = "MyThreadName";
info.szName = "MyThreadName";
to:
ThreadNameInfo.FName := ThreadName; info.szName = ThreadName;
info.szName = ThreadName;
To create the thread object
- Create the thread in a suspended state. See Executing Thread Objects.
- Assign a name, such as:
MyThread.ThreadName := 'SearchForFiles';
MyThread.ThreadName="SearchForFiles";
- Resume the thread. See Starting and Stopping Threads.