用API测试是否连接网络!

uses Wininet;

{$R *.dfm}

function NetWorkIsConnect(Url:string='http://www.microsoft.com/'): 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(PWideChar(Url), 1, 0) then
Result := True;
end;
原文地址:https://www.cnblogs.com/prtmon/p/2264043.html