判断能否上网函数的问题???(20分)

  • 主题发起人 主题发起人 doglive
  • 开始时间 开始时间
D

doglive

Unregistered / Unconfirmed
GUEST, unregistred user!
/返回true则上网,否则false
function TFzjm.NetInternetConnected : boolean;
const
// local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM = 1;
// local system uses a local area network to connect to the Internet.
INTERNET_CONNECTION_LAN = 2;
// local system uses a proxy server to connect to the Internet.
INTERNET_CONNECTION_PROXY = 4;
// local system's modem is busy with a non-Internet connection.
INTERNET_CONNECTION_MODEM_BUSY = 8;
var
dwConnectionTypes : DWORD;
begin
dwConnectionTypes := INTERNET_CONNECTION_LAN+INTERNET_CONNECTION_MODEM
+INTERNET_CONNECTION_PROXY;
//Result := InternetGetConnectedState(@dwConnectionTypes, 1);
Result := InternetGetConnectedState(@dwConnectionTypes, 0);
end;
我用这个函数来判断是否上网状态,可是编译的时候出现这样的错误:
[Error] uzjm.pas(132): Undeclared identifier: 'InternetGetConnectedState'
[Fatal Error] exam_dengji.dpr(12): Could not compile used unit 'uzjm.pas'
请问是为什么呢?
是不是少了个单元文件?该用哪个单元文件呢?
 
试试
uses wininet;
 
unit u_InetState;

interface

uses Classes, SysUtils, Variants,WinInet;


{INTERNET_CONNECTION_MODEM,INTERNET_CONNECTION_LAN,INTERNET_CONNECTION_PROXY,INTERNET_CONNECTION_MODEM_BUSY}

type TConnState=(csModem,csLan,csProxy,csModemBusy,csNotConnected);

type TInetState=class
private
FState:TConnstate;

// procedure SetState(AState:TConnstate);
function isModem:Boolean;
function isLan:Boolean;
function isProxy:Boolean;
function IsModemBusy:Boolean;
public
property ConnectedState:TConnstate read FState {write SetState};
function IsConnected:Boolean;
constructor Create;
end;

implementation

{ TInetState }

constructor TInetState.Create;
begin
inherited;
if isLan then FState:=csLan
else if isModem then FState:=csModem
else if isProxy then FState:=csProxy
else if IsModemBusy then FState:=csModemBusy
else
FState:=csNotConnected;
end;

function TInetState.IsConnected: Boolean;
begin
Result:=(FState<>csNotConnected);
end;

function TInetState.isLan: Boolean;
var
LAN:Integer;
begin
LAN:=INTERNET_CONNECTION_LAN;
Result:=InternetGetConnectedState(@LAN,0);
end;

function TInetState.isModem: Boolean;
var
Modem:Integer;
begin
Modem:=INTERNET_CONNECTION_MODEM;
Result:=InternetGetConnectedState(@Modem,0);
end;

function TInetState.IsModemBusy: Boolean;
var
ModeMBusy:Integer;
begin
ModeMBusy:=INTERNET_CONNECTION_MODEM_BUSY;
Result:=InternetGetConnectedState(@ModeMBusy,0);
end;

function TInetState.isProxy: Boolean;
var
Proxy:Integer;
begin
Proxy:=INTERNET_CONNECTION_PROXY;
Result:=InternetGetConnectedState(@Proxy,0);
end;


{procedure TInetState.SetState(AState: TConnstate);
begin

end;}

end.
 
我都是用上面这个类来判断网络状态~
 
后退
顶部