delphi 判断网络连接

uses WinInet;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if InternetGetConnectedState(nil, 0) then ShowMessage('已连接');
end;

function NetWorkIsConnect: Boolean; 
var 
  ConTypes : Integer; 
begin 
  Result := false; 
  ConTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN + INTERNET_CONNECTION_PROXY; 
if InternetGetConnectedState(@ConTypes, 0) then //ConTypes := $01 + $02 + $04; 
  Result := True 
else 
if InternetCheckConnection('http://www.microsoft.com/', 1, 0) then 
  Result := True; 
end;

 

 

posted @ 2013-05-07 13:39  ftwsnow  阅读(352)  评论(0编辑  收藏  举报