Witam wszystkich serdecznie.

Mam problem z aplikacją służącą do odpytywania hostów za pomocą polecenia ping. Pinguje ona adres IP w zadanym interwale czasowym.

Na tą chwile wygląda ona tak:

user image

Wszystko jest ok do momentu, gdy host nie odpowiada - aplikacja staje deba do momentu uzyskania

AReplyStatus.BytesReceived = 0

Nie można wtedy nic zrobić - nie działa żaden przycisk.

Probowałem użyć wątków, jednak zadanie mnie przerosło - Pojawiał sie komunikat o błędzie - klasa TIdIcmpClient jest niedostępna (lub zbliżony, nie pamiętam dokładnie).

Oto kod aplikacji:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdRawBase, IdRawClient,
  IdIcmpClient, StdCtrls, ExtCtrls, StrUtils, Mask;

type
  TForm1 = class(TForm)

    IdIcmpClient1: TIdIcmpClient;
    Timer1: TTimer;
    Interwal: TEdit;
    Button1: TButton;
    Button2: TButton;
    GroupBox2: TGroupBox;
    GroupBox1: TGroupBox;
    Memo1: TMemo;
    NazwaHost1: TMaskEdit;
    Label2: TLabel;

    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

    procedure PingReply(ASender: TComponent; const AReplyStatus: TReplyStatus);
    procedure Timer1Timer(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

  Host : Integer;
  NumerPola: Integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Enabled := False;
  Host := 1;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
  Button1.Enabled := True;
  Host := 0;
end;

procedure TForm1.PingReply(ASender: TComponent; const AReplyStatus: TReplyStatus);
begin
  if AReplyStatus.BytesReceived = 0 then

    begin
    TMemo(Form1.FindComponent('Memo'+IntToStr(NumerPola))).Lines.Add('Upłynął limit.');
    end
  else
  TMemo(Form1.FindComponent('Memo'+IntToStr(NumerPola))).Lines.Add(Format('%d bajtów odebranych z %s w %d ms',
  [AReplyStatus.BytesReceived, AReplyStatus.FromIpAddress, AReplyStatus.MsRoundTripTime]));
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Interval :=StrToInt(Interwal.Text)*1000;

  If Host = 1 Then
  begin
    NumerPola := 1;
    IdIcmpClient1.Host := AnsiReplaceStr(NazwaHost1.Text, ' ', ''); // przypisujemy hosta
    IdIcmpClient1.Ping; // wysyłamy sygnał ping
  end;

end;

end.

Za wszelkie wskazówki i podpowiedzi będę bardzo wdzięczny.

Pozdrawiam!