I can't get NameThread to work

delphi package - automated exception handling
Post Reply
rossmcm
Posts: 74
Joined: Thu Jun 09, 2005 2:05 am
Contact:

I can't get NameThread to work

Post by rossmcm »

It must be something simple I'm doing wrong, surely.

Running Delphi 2007. I call NameThread just after my thread has been created:

Code: Select all

MadExcept.NameThread (ThreadID, ThreadName) ; 
but calling GetThreadName

Code: Select all

function  TMyThread.GetThreadName  : string ;

begin
Result := MadExcept.GetThreadName (ThreadID) ;
end ;
always returns "Thread $xxxx". Is there anyway I can troubleshhoot this further?
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: I can't get NameThread to work

Post by madshi »

Just tested this with Delphi 2007 on my PC (Windows 8.1 x64):

Code: Select all

uses madExcept;

var tid : dword;

function TestThread(dummy: pointer) : NativeInt; stdcall;
begin
  SuspendThread(GetCurrentThread);
end;

procedure TForm3.Button1Click(Sender: TObject);
begin
  CloseHandle(CreateThread(nil, 0, @TestThread, nil, 0, tid));
  NameThread(tid, 'TestThreadBla');
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
  Caption := GetThreadName(tid);
end;

end.
Works just fine here. Of course madExcept needs to be enabled for this to work.
rossmcm
Posts: 74
Joined: Thu Jun 09, 2005 2:05 am
Contact:

Re: I can't get NameThread to work

Post by rossmcm »

<red-face>Of course..... </red-face>

Thanks Matthias.
Post Reply