سلام
من برنامه خودم رو با Thread نوشتم ولی ظاهراً این Thread اجرا نمیشه، لطفاً کد من رو بررسی کنید ببینیم چه مشکلی داره؟
unit untPingThread;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Strutils, IdIcmpClient;
type
Thamidreza = class(TThread)
private
{Protected}
Protected
Procedure Execute; override;
function Reply(): string;
Public
Ip,ReplyString: String;
Procedure Result;
end;
Var
IndyIcmp_ping: TIdIcmpClient;
implementation
{$R *.dfm}
Procedure Thamidreza.Execute;
Var
I: integer;
Begin
for I := 1 to 254 do
begin
try
IndyIcmp_ping.Create(Application);
IndyIcmp_ping.Host := Ip;
IndyIcmp_ping.ReceiveTimeout := 1000;
IndyIcmp_ping.Ping();
Synchronize(Result);
Except
//ReplyString := ('Host Not Avalable');
end;
end;
end;
function Thamidreza.Reply(): string;
begin
case IndyIcmp_ping.ReplyStatus.ReplyStatusType of
rsEcho:
begin
Result := (format('Reply from %s :Time< %d millisec.',
[IndyIcmp_ping.ReplyStatus.FromIpAddress, IndyIcmp_ping.ReplyStatus.MsRoundTripTime]));
end;
rsError:
Result := ('Unknown error.');
rsTimeOut:
Result := ('Timed out.');
rsErrorUnreachable:
Result := (format('Host %s reports destination network unreachable.',
[IndyIcmp_ping.ReplyStatus.FromIpAddress]));
rsErrorTTLExceeded:
Result := (format('Hope %d %s: TTL expired.',
[IndyIcmp_ping.ReplyStatus.FromIpAddress]));
end;
end;
Procedure Thamidreza.Result;
Begin
ReplyString := Reply();
End;
{------------------------------------------------------}
procedure TForm1.btnPingClick(Sender: TObject);
var
h:Thamidreza;
begin
h:=Thamidreza.Create(true);
h.Ip := GetIpfromEditbox(edt_PING_IpAddress.Text);
h.FreeOnTerminate := True;
h.Resume;
lst_PING_Reply.Items.Append(h.ReplyString);
end;