TThread.NameThreadForDebugging is great for telling threads apart, but not all of my threads are TThread descendants. I have some that are created by an external library that's not even written in Delphi. Is there any way to name them if I can find a way to get their thread handles?
+6
A:
See this MSDN article: How to: Set a Thread Name in Native Code
This works for Visual Studio. I don't know whether the Delphi debugger will pick up the name.
Note that you need the thread ID rather than the thread handle.
Kristopher Johnson
2010-04-13 22:35:00
Yeah, the Delphi RTL function appears to be almost an exact translation of this bit of C++. But in the helpfile it says "ThreadID is the ThreadID property of the TThread instance to be named." So is that just a reflection of a thread ID assigned by Windows?
Mason Wheeler
2010-04-13 22:42:36
Yes, Mason. TThread's ID property is the Windows thread ID.
Rob Kennedy
2010-04-13 22:47:22
You might want to be aware of following quirk - I am not sure if it applies to Delphi debugger as well: http://stackoverflow.com/questions/2448155/setthreadname-not-working-with-visual-studio-2005
Suma
2010-04-14 13:57:30
No, that looks to be specific to Visual Studio.
Mason Wheeler
2010-04-14 16:02:49