1. Home
  2. Computing & Technology
  3. Delphi Programming

Are we connected to the Internet?

By , About.com Guide

Here's how to check whether you are connected to the Internet:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button1Click(Sender: TObject) ;

  function FuncAvail(_dllname, _funcname: string;
                     var _p: pointer): boolean;
  {return True if _funcname exists in _dllname}
  var _lib: tHandle;
  begin
   Result := false;
   if LoadLibrary(PChar(_dllname)) = 0 then exit;
   _lib := GetModuleHandle(PChar(_dllname)) ;
   if _lib <> 0 then begin
    _p := GetProcAddress(_lib, PChar(_funcname)) ;
    if _p <> NIL then Result := true;
   end;
  end;

  {
  Call SHELL32.DLL for Win < Win98
  otherwise call URL.dll
  }
  {button code:}
  var
   InetIsOffline : function(dwFlags: DWORD):
                   BOOL; stdcall;
  begin
   if FuncAvail('URL.DLL', 'InetIsOffline',
                @InetIsOffline) then
    if InetIsOffLine(0) = true
     then ShowMessage('Not connected')
     else ShowMessage('Connected!') ;
  end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Activate Windows Start button from code
« Use TTF without installing

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2000 Delphi Tips
  7. Are we connected to the Internet? Check using Delphi code.

©2009 About.com, a part of The New York Times Company.

All rights reserved.