在D7中怎样用API检测本机是否连上互联网??

解决方案 »

  1.   

    ping一个可以ping通的外网网址(如www.google.com)就可以了
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
       Types : Integer;
    begin
    {    CopyRight (C) Bowman      }
    {    [email protected]    }
       Types := INTERNET_CONNECTION_MODEM +
                INTERNET_CONNECTION_LAN +
                INTERNET_CONNECTION_PROXY;
       //check 3 conditions together
        if InternetGetConnectedState(@types, 0) then
           Edit1.Text := 'your pc is Online now'
        else
           Edit1.Text := 'your pc is offline now';
    end;
      

  3.   

    方法二:
    procedure TForm1.Button1Click(Sender: TObject); 
    begin 
    if GetSystemMetrics(SM_NETWORK) and $0001 = $0001 then
       edit1.text:='Machine is OnLine'
    else
       edit1.text:='Machine is OffLine';
    end;