Is it correct to set the stream name in Delphi 6?

I want a nice convenient name to appear in the thread list window, and in the Delphi 6 IDE. I found the code below on the Internet for this in Delphi 6, since, as far as I know, this version does not have SetThreadName () initially. I call it from my Execute () method. I know what this is called because the IDE appears when an exception occurs. However, when I look in the list of threads (Ctrl + Alt + T), I do not see the name that I gave. I just see the regular columns Id, State, Status and Location Thread, nothing more.

What do I need to do differently to get stream names? Also, does anyone have an idea on how to stop the IDE from pausing a RaiseException string? I have many threads in the program, and it is annoying when the IDE appears every time every time I run the program.
I know that I can disconnect the IDE from stopping in Delphi Exceptions, but I want it to be normal, and I would prefer not to switch this every time a new set of threads is created.

Delphi named threads - what is it?

procedure SetThreadName_delphi(const Name: string); type TThreadNameInfo = record RecType: LongWord; Name: PChar; ThreadID: LongWord; Flags: LongWord; end; var info:TThreadNameInfo; begin // This code is extremely strange, but it the documented way of doing it! info.RecType := $1000; info.Name := PChar(Name); info.ThreadID := $FFFFFFFF; info.Flags := 0; try RaiseException($406D1388, 0, SizeOf(info) div SizeOf(LongWord), PDWord(@info)); except end; end; 
+7
source share
2 answers

I found the source code

This is an exception for a specific application (this means that it is specific to the Visual C ++ compiler). I see no reason why Delphi should support this strange function (although it is possible).


Edit: BUT THIS WORKS! (thanks Remy Lebo)

Just tested on Delphi XE (I see "Wow!" In the debug window "Topic Status"):

 unit NameTest; interface uses Windows, Classes; type TTestThread = class(TThread) private { Private declarations } protected procedure Execute; override; end; implementation { TTestThread } procedure SetThreadName_delphi(const Name: string); type TThreadNameInfo = record RecType: LongWord; Name: PAnsiChar; ThreadID: LongWord; Flags: LongWord; end; var info:TThreadNameInfo; AnsiName: AnsiString; begin AnsiName:= Name; info.RecType := $1000; info.Name := PAnsiChar(AnsiName); info.ThreadID := $FFFFFFFF; info.Flags := 0; try RaiseException($406D1388, 0, SizeOf(info) div SizeOf(LongWord), PDWord(@info)); except end; end; procedure TTestThread.Execute; begin SetThreadName_delphi('Wow!'); while not Terminated do Sleep(1000); end; end. 
+6
source

In C ++ Builder 6 and Delphi 7, the File > New > Other > Thread Object wizard has the ability to name a new thread in the debugger. The wizard generates a descendant TThread stub TThread with the necessary implementation of RaiseException() at the top of its Execute() method.

This is not some help for Delphi 6, although it has not yet supported the thread.

+5
source

All Articles