procedure TForm1.Button1Click(Sender: TObject);
begintry
idsocksinfo1.Version:=svsocks5;
idiohandlersocket1.SocksInfo:=idsocksinfo1;
idhttp1.IOHandler:=idiohandlersocket1;
idsocksinfo1.Host:='84.115.66.192' ;
idsocksinfo1.Port:=56228 ;try
memo1.Lines.Add(idhttp1.Get('http://www.baidu.com')) ;
except
showmessage('error')endfinally
idhttp1.free;end;
end ;
我想在 尝试连接代理 不成功的时候 提示一个showmessage 为什么我写的这一段 没有提示error 只有个异常处理 如何修改才能 实现 如果代理不成功 则do other呢
begintry
idsocksinfo1.Version:=svsocks5;
idiohandlersocket1.SocksInfo:=idsocksinfo1;
idhttp1.IOHandler:=idiohandlersocket1;
idsocksinfo1.Host:='84.115.66.192' ;
idsocksinfo1.Port:=56228 ;try
memo1.Lines.Add(idhttp1.Get('http://www.baidu.com')) ;
except
showmessage('error')endfinally
idhttp1.free;end;
end ;
我想在 尝试连接代理 不成功的时候 提示一个showmessage 为什么我写的这一段 没有提示error 只有个异常处理 如何修改才能 实现 如果代理不成功 则do other呢
还有一点就是你的异常处理,修改为:try
//
except
on E: Exception do
begin
ShowMessage(E.Message);//或者采用下面的方式;
if E.Message = XXX then
begin
//对应错误代码需要查询错误代码库。
end;
end;
end
//可用来检测网络连接是否正确,InternetCheckConnection函数检查不准确,有些情况无法检测到,而以下CheckUrl函数则不会。
//uses wininet;
function CheckUrl(url: string): Boolean;
var
hSession, hfile, hRequest: hInternet;
dwindex, dwcodelen: dword;
dwcode: array[1..20] of Char;
res: PChar;
begin
Result := false;
if Pos('http://', LowerCase(url)) = 0 then url := 'http://' + url;
hSession := InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, 0);
if Assigned(hsession) then
begin
hfile := InternetOpenUrl(hsession, PChar(url), nil, 0, INTERNET_FLAG_RELOAD, 0);
dwIndex := 0;
dwCodeLen := 10;
HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex);
res := PChar(@dwcode);
Result := (res = '200') or (res = '302'); //200,302未重定位标志
if Assigned(hfile) then
InternetCloseHandle(hfile);
InternetCloseHandle(hsession);
end;
end;