RAD Studio |  |

Assigning Separate Names to Similar Threads
See Also
Collapse All

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:

Copy Code

    property ThreadName: string read FName write FName;

Copy Code

    __property AnsiString ThreadName = {read=FName, write=FName};

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

Copy Code

    ThreadNameInfo.FName := 'MyThreadName';

Copy Code

    info.szName = "MyThreadName";

to:

Copy Code

    ThreadNameInfo.FName := ThreadName;

Copy Code

    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.

See Also

Converting an Unnamed Thread to a Named Thread

Naming a Thread

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