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;

 

 

你可能感兴趣的:(Delphi)