title: delphi check internet connection
body: <p>I need a working function for Delphi 2010 to check if there is Internet connection available.</p>
  
  <p>I say working because so far I tried 4 different methods e.g. <a href="http://delphi.about.com/b/2005/04/22/how-to-check-for-internet-connection-using-delphi-code.htm" rel="nofollow">http://delphi.about.com/b/2005/04/22/how-to-check-for-internet-connection-using-delphi-code.htm</a> but neither worked.</p>
  
  <p>For example one method alway gave back that there was internet connection even when the cable was not in the pc, the other the opposite (it always said there was no connection).</p>
  
  <pre><code>     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 &lt;&gt; 0 then begin
          _p := GetProcAddress(_lib, PChar(_funcname)) ;
          if _p &lt;&gt; NIL then Result := true;
         end;
        end;
  
        {
        Call SHELL32.DLL for Win &lt; 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;
  </code></pre>