通过IP地址来判断。
首先要明确的是IP地址可能有两种:网卡配的或拨号服务器配的。
如果是拨号,可以使用RAS函数查看拨号服务器给你分配的IP地址;
如果是专线,当然也可以通过IP地址,这要通过WNET函数。但这不是肯定的。只好尝试一下PING网关或某一个已存在的主机。这要通过ICMP.DLL提供的函数。
曾经看过有一种方法是看注册表,来判断是否上网(应该是拨号),但具体怎么做,就不是很记得了,也没实验过。

解决方案 »

  1.   

    使用下面的两个函数就可以:
    例如:
    if not inetisoffline then 
       showmessage('已经上网');
    另外一个函数用法差不多。
    //声明:
    function InetIsOffline(res:dword=0):boolean;stdcall;external 'url.dll' name 'InetIsOffline';function InternetGetConnectedState;stdcall;external 'wininet.dll' name 'InternetGetConnectedState';
      

  2.   

    哦,忘记了,还有一点儿:function InternetGetConnectedState(uflag:dword;reverse:dword):boolean;stdcall;function InetIsOffline(res:dword=0):boolean;stdcall;
      

  3.   

    这两个函数要自己声明的,我都已经帮你写出来了!
    function InetIsOffline(res:dword=0):boolean;stdcall;external 'url.dll' name 'InetIsOffline';function InternetGetConnectedState(uflag:dword;reverse:dword);stdcall;external 'wininet.dll' name 'InternetGetConnectedState';
      

  4.   

    在implementation下面声明即可:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}function InetIsOffline(res:dword=0):boolean;stdcall;external 'url.dll' name 'InetIsOffline';function InternetGetConnectedState(uflag:dword;reverse:dword):boolean;stdcall;external 'wininet.dll' name 'InternetGetConnectedState';procedure TForm1.Button1Click(Sender: TObject);
    begin
    if not inetisoffline then
      showmessage('already connect to Internet');
    end;end.
      

  5.   

    如果还不明白,我#%@^$E@%&^&@
    ^_^,别忘了给分!