Assigning Separate Names to Similar Threads

From RAD Studio
Jump to: navigation, search

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

  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};
    
    __property AnsiString ThreadName = {read = FName, write = FName};
    
  2. 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

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

See Also