Показать сообщение отдельно
  #4  
Старый 25.02.2011, 23:10
Assistant Assistant вне форума
Продвинутый
 
Регистрация: 20.02.2011
Адрес: там где правят идиоты
Сообщения: 603
Версия Delphi: 7
Репутация: выкл
По умолчанию

самый простой и примитивный способ:
Код:
 type
   TMyThread = class(TThread)
     host: string;
     port: integer;
     isalive: boolean;
   public
     procedure ToLog;
   protected
     procedure Execute; override;
   end;

..........................

procedure TMyThread.ToLog;
begin
  if isalive then
    Form1.Memo1.Lines.Add(host + ' at port ' + IntToStr(port) + ' is alive')
  else
    Form1.Memo1.Lines.Add(host + ' at port ' + IntToStr(port) + ' is NOT alive');
end;

procedure TMyThread.Execute;
var
  IdTCPClient: TIdTCPClient;
begin
  isalive := False;
  FreeOnTerminate := True;
    IdTCPClient := TIdTCPClient.Create(nil);
    IdTCPClient.Host := host;
    IdTCPClient.Port := port;
    try
      IdTCPClient.Connect;
      if IdTCPClient.Connected then
        isalive := True
    except
      isalive := False;
    end;
    IdTCPClient.Free;
    Synchronize(ToLog);
end;

Код:
var
  ping: TMyThread;
  i: integer;
begin
  for i:=1 to 100 do
  begin
    ping := TMyThread.Create(True);
    ping.host := 'localhost';
    ping.port := i;
    ping.Resume;
  end;
Ответить с цитированием