//需要引用 Winapi.Windows 和 Winapi.WinInet两个单元
var
Winapi.Windows,Winapi.WinInet;
//函数实现
function IsNetworkConnected(var AMsg:string): Boolean;
var
Flags: DWORD;
begin
AMsg := '';
Result := False;
if InternetGetConnectedState(@Flags, 0) then
begin
if ((Flags and INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM) then
begin
AMsg := '在线(拨号)';
Result := True;
end;
if ((Flags and INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN) then
begin
AMsg := '在线(局域网)';
Result := True;
end;
if ((Flags and INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY) then
begin
AMsg := '在线(代理)';
Result := True;
end;
end;
end;
//调用/使用
var
_NetStates : Boolean;
_sMsg : string;
begin
_NetStates := IsNetworkConnected(_sMsg);
end
Pascal