views:

134

answers:

1

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
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
Yes, Mason. TThread's ID property is the Windows thread ID.
Rob Kennedy
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
No, that looks to be specific to Visual Studio.
Mason Wheeler