📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent, IdRawBase,
IdRawClient, IdIcmpClient, SkinCaption, WinSkinData;
type
TForm1 = class(TForm)
Edit1: TEdit;
Panel1: TPanel;
Button1: TButton;
Label1: TLabel;
Button2: TButton;
ICMP: TIdIcmpClient;
ListBox1: TListBox;
SkinData1: TSkinData;
SkinCaption1: TSkinCaption;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ICMPReply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
ICMP.Host := Edit1.Text ; //宿主计算机的名称或IP地址
ICMP.ReceiveTimeout := 1000; //最大等待时间
Button1.Enabled := false;
try
for i:=0 to 3 do //重复4次
begin
ICMP.Ping ;
Application.ProcessMessages ; //延时
end;
finally
Button1.Enabled := true;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ListBox1.Clear ;
end;
procedure TForm1.ICMPReply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
var
sTime: string;
begin
//检测Ping的回复错误
if (AReplyStatus.MsRoundTripTime = 0 ) then
sTime := '<1'
else
sTime := '=';
//在列表框中显示Ping消息
ListBox1.Items.Add(Format('ICMP_SEQ=%d Reply from %s [%s] : Bytes=%d time%s%d ms TTL=%d',
[AReplyStatus.SequenceId,
Edit1.Text,
AReplyStatus.FromIpAddress,
AReplyStatus.BytesReceived,
sTime,
AReplyStatus.MsRoundTripTime,
AReplyStatus.TimeToLive]));
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -