DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

CheckInternetConnection

Checks if a computer is connected to the internet by trying to resolve the name of the web host specified by AHost.

function CheckInternetConnection(AHost: PAnsiChar): Boolean;
var
  PHE: PHostEnt;
  GInitData: TWSAData;
begin
  WinSock.WSAStartup($101, GInitData);
  PHE := WinSock.GetHostByName(AHost);
  WinSock.WSACleanup;
  Result := (PHE <> nil);
end;

IsInternetConnected

Checks if a computer is connected to the internet.

function IsInternetConnected: Boolean;
var
  Flags: Windows.DWORD; // flags to pass to API function
begin
  Flags := 0;
  Result := WinInet.InternetGetConnectedState(@Flags, 0);
end;

View the whole database.

Go to the DelphiDabbler website.