procedure SetCurrentThreadName(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's 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;
Let's hope it gets easier to find on Google now.
4 comments:
Also see CC16302: Human readable thread identifiers in debugger
Cool ! Thanks a lot.
btw, exactly that code gets added by Delphi's "New Thread Object" wizard.
I believe that's available since at least Delphi 7 - I never checked the docs though :-)
Yes, Indy uses a similar code too. Citation from idGlobal.pas:
{$IFDEF MSWINDOWS}
with LThreadNameInfo do begin
RecType := $1000;
Name := PChar(AName);
ThreadID := $FFFFFFFF;
Flags := 0;
end;
try
// This is a wierdo Windows way to pass the info in
RaiseException($406D1388, 0, SizeOf(LThreadNameInfo) div SizeOf(LongWord),
PDWord(@LThreadNameInfo));
except end;
{$ENDIF}
Post a Comment