I am using Indy9 with Delphi7. I would like to cast an Longword (Athread.Handle) back to an TIDPEERTHREAD Pointer. Is there a way how I could do this? Or is there any other way I could "store" the Pointer to a Longword?
Thank you in Advance.
TIdPeerThread
is a TThread
descendant. Its Handle
property contains the OS-level thread handle from CreateThread()
. There is no way to cast a Handle
value directly to a TIdPeerThread
object pointer. You will have to either:
1) Store the TIdPeerThread
object pointer itself in the LongWord
instead of the TIdPeerThread.Handle
value, and then cast it back when needed:
var
LW: LongWord;
Peer: TIdPeerThread;
Peer := ...;
LW := LongWord(Peer);
...
Peer := TIdPeerThread(LW);
2) Store the TIdPeerThead.Handle
value in the LongWord
, then loop through the TIdTCPServer.Threads
list looking for a TIdPeerThread
object that has a matching value when needed:
var
LW: LongWord;
Peer: TIdPeerThread;
List: TList;
I: Integer;
Peer := ...;
LW := LongWord(Peer.Handle);
...
Peer := nil;
List := IdTCPServer1.Threads.LockList;
try
for I := 0 to List.Count-1 do
begin
if LongWord(TIdPeerThread(List[I]).Handle) = LW then
begin
Peer := TIdPeerThread(List[I]);
Break;
end;
end;
finally
IdTCPServer1.Threads.UnlockList;
end;