was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

53 Visitors Online


 
...überprüfen, ob eine Verbindung zum Internet besteht (3)?
Autor: bnOne
Homepage: http://kickme.to/bnOne
[ Tip ausdrucken ]  

Tip Bewertung (19):  
     


{2. Static linking. }

uses
  
WinInet;

{...}

function IsConnectedToInternet: Boolean;
var
  
dwConnectionTypes: DWORD;
begin
  
dwConnectionTypes :=
    INTERNET_CONNECTION_MODEM +
    INTERNET_CONNECTION_LAN +
    INTERNET_CONNECTION_PROXY;
  Result := InternetGetConnectedState(@dwConnectionTypes, 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
IsConnectedToInternet then
    
ShowMessage('Connected.')
  else
    
ShowMessage('Not Connected.')
end;

{**********************************************************}
{2. Dynamic linking. }

function IsConnectedToInternet(lpdwFlags: LPDWORD): Boolean;
const
  
WininetDLL = 'wininet.dll';
var
  
hWininetDLL: THandle;
  dwReserved: DWORD;
  fn_InternetGetConnectedState: function(lpdwFlags: LPDWORD; dwReserved: DWORD): BOOL; stdcall;
begin
  
Result := False;
  dwReserved := 0;
  hWininetDLL := LoadLibrary(WininetDLL);
  if hWininetDLL > 0 then
  begin
    
@fn_InternetGetConnectedState := GetProcAddress(hWininetDLL,'InternetGetConnectedState');
    if Assigned(fn_InternetGetConnectedState) then
    begin
      
Result := fn_InternetGetConnectedState(lpdwFlags, dwReserved);
    end;
    FreeLibrary(hWininetDLL);
  end else
   raise 
Exception.Create('Unable to locate function InternetGetConnectedState in library ' + WininetDLL);

end;

procedure TForm1.Button1Click(Sender: TObject);
const
  
INTERNET_CONNECTION_MODEM = 1;
  INTERNET_CONNECTION_LAN = 2;
  INTERNET_CONNECTION_PROXY = 4;
  INTERNET_CONNECTION_MODEM_BUSY = 8;
var
  
dwConnectionTypes: DWORD;
begin
  
dwConnectionTypes :=
    INTERNET_CONNECTION_MODEM +
    INTERNET_CONNECTION_LAN +
    INTERNET_CONNECTION_PROXY;
  if IsConnectedToInternet(@dwConnectionTypes) then
    
ShowMessage('Connected.')
  else
    
ShowMessage('Not Connected.')
end;






Other Possibilities/ Andere Möglichkeiten:
...determine if there is an active connection to the internet ?
...überprüfen ob eine Verbindung zum Internet besteht ?

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners