手机端判断是否连接internet网络

uses
 IdTCPClient;


function TForm1.checkinternet: Boolean;
var
  tmpidclient: TIdTCPClient;
begin
  Result := False;

  try
    try
      tmpidclient := TIdTCPClient.Create(nil);
      tmpidclient.ReadTimeout := 2000;
      tmpidclient.ConnectTimeout := 2000;
      tmpidclient.Port := 80;
      tmpidclient.Host := 'www.baidu.com';
      tmpidclient.Connect;
      tmpidclient.Disconnect;
      Result := true;
    except
      on e: Exception do
      begin
        Result := False;
      end;

    end;
  finally
    tmpidclient.DisposeOf;
    tmpidclient := nil;
  end;
end;
发布了303 篇原创文章 · 获赞 59 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/winniezhang/article/details/104166312