type
PPingThreadParam = ^TPingThreadParam;
TPingThreadParam =
record
IP:
string;
Ping: Integer;
end;
//...
function PingThread(Param: PPingThreadParam): Integer;
begin
try
Param.Ping := u_retPing.ICMPPingRTT(u_retPing.DNSNameToIp(Param.IP), Cardinal(1000));
Result := Ord(True);
except
Result := Ord(False);
end;
end;
//...
procedure Test();
var
Param: TPingThreadParam;
Thread: THandle;
ThreadId: DWORD;
ThreadExit: DWORD;
begin
Param.IP := '
127.0.0.1';
Thread := THandle(
BeginThread(
nil, 0, TThreadFunc(@PingThread), @Param, 0, ThreadId));
if Thread <> 0
then
try
while WaitForSingleObject(Thread, 10) = WAIT_TIMEOUT
do
Application.ProcessMessages();
if not GetExitCodeThread(Thread, ThreadExit)
then
ThreadExit := Ord(False);
if Boolean(ThreadExit)
then
ShowMessage('
Ping: ' + IntToStr(Param.Ping))
else
ShowMessage('
PingThread failed');
finally
CloseHandle(Thread);
end;
end;