Thursday, September 10, 2009

Connected to Internet?

Sometimes you need to know if the computer on which your program is running has Internet connection in order to check for updates connect to a server and serve as slave :)
Add "WinInet" to uses clause.
function ConnectedToNet: boolean;
var
  flags: DWORD;
begin
  Flags :=
    INTERNET_CONNECTION_MODEM or
    INTERNET_CONNECTION_LAN or
    INTERNET_CONNECTION_PROXY or
    INTERNET_CONNECTION_MODEM_BUSY;
  result := InternetGetConnectedState(@Flags, 0);
end;

Usage
 ShowMessage(BoolToStr(ConnectedToNet, True));

No comments:

Post a Comment

Blogroll(General programming and Delphi feeds)