Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Программирование и базы данных (http://forum.oszone.net/forumdisplay.php?f=21)
-   -   Как определить, Internet connected or disconnected? (http://forum.oszone.net/showthread.php?t=29414)

IkaMazini 05-10-2004 23:47 203829

Как в Delphi определить Internet connected or disconnected?

[mzd] 06-10-2004 10:50 203830

Help me! Internet connection!
 
Почитай здесь http://interdelphi.h11.ru/inet.html
Или, если этого мало, то зайди сюда Google рулит не по детски :)

IkaMazini 06-10-2004 13:08 203831

Help me! Internet connection!
 
[mzd] THX

IkaMazini 06-10-2004 16:13 203832

SOS! Мне нужен реальный код!
 
Мне нужен реальный код, чтобы проверять Интернет соединение “Connected”, “Not Connected” или “Disconnected”! Windows XP. Delphi 7. Internet.
Что-то вроде етаго,  но это дрянь в WinXP-е не работает:

function InetIsOffline(Flag: Integer): Boolean; stdcall; external 'URL.DLL';

procedure TForm1.Button1Click(Sender: TObject);
begin
 if InetIsOffline(0) then
 showMessage('This computer is not connected to Internet!')
else
 showMessage('You are connected to Internet!');
end;


vadimiron 07-10-2004 01:10 203833

SOS! Мне нужен реальный код!
 
Я не программирую в Дельфи, но в немецком инете нашёл следущее, может это то, что нужно
Код:

Function Connection: boolean;

var

flags: dword;

begin

result:= InternetGetConnectedState(@flags, 0);

end;

Добавлено:

А ещё такое нашёл
Код:

interface
uses
Windows,SysUtils,Registry,WinSock,WinInet;
type
  TConnectionType=(ctNone,ctProxy,ctDialup);
function ConnectedToInternet:TConnectionType;
function RasConnectionCount:Integer;

implementation
// For RasConnectionCount = = = = = = = = = = = = = = = = = = = = = = =
const
cERROR_BUFFER_TOO_SMALL=603;
cRAS_MaxEntryName=256;
cRAS_MaxDeviceName=128;
cRAS_MaxDeviceType=16;
type
  ERasError=class( Exception);
  HRASConn=DWord;
  PRASConn=^TRASConn;
  TRASConn=record
  dwSize:DWORD;
  rasConn:HRASConn;
  szEntryName:Array[0..cRAS_MaxEntryName]Of Char;
  szDeviceType:Array[0..cRAS_MaxDeviceType]Of Char;
  szDeviceName:Array[0..cRAS_MaxDeviceName]of char;
end;
TRasEnumConnections=
function (RASConn:PrasConn;{ buffer to receive Connections data }
var BufSize:DWord;{ size in bytes of buffer }
  var Connections:DWord { number of Connections written to buffer }
  ):LongInt;stdcall;
  // End RasConnectionCount = = = = = = = = = = = = = = = = = = = = = = =
  
function ConnectedToInternet:TConnectionType;
var
  Reg:TRegistry;
  bUseProxy:Boolean;
  UseProxy:LongWord;
begin
  Result:=ctNone;
  Reg:=TRegistry.Create;
  with REG do
  try
    try
      RootKey:=HKEY_CURRENT_USER;
      if OpenKey( '\Software\Microsoft\Windows\CurrentVersion\Internet settings',False) then begin
        // I just try to read it , and trap an exception
        if GetDataType( 'ProxyEnable')=rdBinary then
        ReadBinaryData( 'ProxyEnable',UseProxy,SizeOf( LongWord))
        else begin
          bUseProxy:=ReadBool( 'ProxyEnable');
          if bUseProxy then
          UseProxy:=1
          else
          UseProxy:=0;
        end;
        if (UseProxy<>0) and (ReadString( 'ProxyServer')<>'') then Result:=ctProxy;
      end;
    except
      // Obviously not connected through a proxy
      end;
    finally
      Free;
    end;
    // We can check RasConnectionCount even if dialup networking is not installed
    // simply because it will return 0 if the DLL is not found .
    if Result=ctNone then begin
      if RasConnectionCount>0 then Result:=ctDialup;
    end;
  end;
function RasConnectionCount:Integer;
var
  RasDLL:HInst;
  Conns:Array[1..4]of TRasConn;
  RasEnums:TRasEnumConnections;
  BufSize:DWord;
  NumConns:DWord;
  RasResult:Longint;
begin
  Result:=0;
  // Load the RAS DLL
  RasDLL:=LoadLibrary( 'rasapi32.dll');
  if RasDLL=0 then exit;
  try
    RasEnums:=GetProcAddress( RasDLL,'RasEnumConnectionsA');
    if @RasEnums=nil then
    raise ERasError.Create( 'RasEnumConnectionsA not found in rasapi32.dll');
    Conns[1].dwSize:=Sizeof (Conns[1]);
    BufSize:=SizeOf( Conns);
    RasResult:=RasEnums( @Conns,BufSize,NumConns);
    If (RasResult=0) or (Result=cERROR_BUFFER_TOO_SMALL) then Result:=NumConns;
  finally
    FreeLibrary( RasDLL);
  end;
end;


IkaMazini 07-10-2004 03:41 203834

vadimiron
 
Большое тебе спасибо, это то что и нужно!

IkaMazini 08-10-2004 14:18 203835

WOW! Ребята вот вам реальны код, чтобы проверять Интернет со
 
uses WinInet;
……………
procedure TForm1.Button1Click(Sender: TObject);
var
*dwConnectionTypes: DWORD;
begin
*if InternetGetConnectedState(@dwConnectionTypes,0) then
* *ShowMessage('Internet Connection Executed!');
*if not InternetGetConnectedState(@dwConnectionTypes,0) then
begin

*if MessageDlg('Internet Connection Not Executed!'
* ,Mtinformation,[mbOk],0)=mrOk then
*Exit;
end;
end;



Время: 03:35.

Время: 03:35.
© OSzone.net 2001-