Einzelnen Beitrag anzeigen

marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#6

Re: probleme mit exceptions und idhttp

  Alt 15. Jul 2008, 19:19
Herzlich willkommen in der Delphi-PRAXiS, Malte.

Vielleicht möchtest du ja nur prüfen, ob ein bestimmter WebServer antwortet. Ich habe deinen Code ein wenig umgeschrieben:

Delphi-Quellcode:
const
  SERVER_STATUS: array [Boolean] of string = ('offline', 'online');
  SERVER_NAME = 'www.delphipraxis.net';

function HttpServerActive(const serverName: string;
    const proxyName: string = ''): Boolean;
begin
  with TIdHTTP.Create(nil) do
  try
    Host := serverName;
    ProxyParams.ProxyServer := proxyName;
    ProxyParams.ProxyPort := Port;
    try
      Head('/');
      Result := True;
    except
      Result := False;
    end;
  finally
    Free;
  end;
end;

procedure TDemoForm.ClockTimer(Sender: TObject);
begin
  with Sender as TTimer do
  begin
    Enabled := False;
    try
      StatusLabel.Caption := SERVER_STATUS[HttpServerActive(SERVER_NAME)];
    finally
      Enabled := True;
    end;
  end;
end;
Freundliche Grüße
  Mit Zitat antworten Zitat