delphi 判断前网络连接状态

2021-04-20 17:27

阅读:576

function GetNetworkState: string; // 得到当前网络连接状态
var
 NS: TNetworkState;
begin
 NS := TNetworkState.Create;
 try
  if not NS.IsConnected then // 无网络
   result := ‘0‘
  else if NS.IsWifiConnected then // wifi
   result := ‘1‘
  else if NS.IsMobileConnected then // 移动数据
   result := ‘2‘;
 finally
   NS.Free;
 end;
end;


评论


亲,登录后才可以留言!