RAD Studio
ContentsIndex
PreviousUpNext
Assigning Separate Names to Similar Threads

All thread instances from the same thread class have the same name. However, you can assign a different name for each thread instance at runtime using the following steps.

To assign separate names to similar threads

  1. 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};

  1. In the SetName method, change where it says:

ThreadNameInfo.FName := 'MyThreadName';

 

info.szName = "MyThreadName";

to:

ThreadNameInfo.FName := ThreadName;

 

info.szName = ThreadName;
To create the thread object

  1. Create it suspended. See Executing Thread Objects.
  2. Assign a name, such as MyThread.ThreadName := 'SearchForFiles';
  3. Resume the thread. See Starting and Stopping Threads.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!