我的程序中有以下代码。当我尝试检查代理是否是有效代理时,它会使我的程序崩溃。任何想法如何解决这一问题?我使用的是印10为什么此代码用于检查代理有效性崩溃?
if checkproxy('http://www.google.com') label1.text:='Good' else label1.text:='bad';
如果我尝试调用另一个idHTTP请求checkproxy崩溃的程序之后连接。
这是实际的代码....这将返回错误......
function TregForm.webSession(sURL : ansistring) : ansistring;
var sstream : Tstringstream;
httpcon : TIdHTTP;
antifreeze : TIdAntiFreeze;
begin
result := '';
sstream := tstringstream.Create('');
try
if length(SettingsForm.edtProxyServer.text) >= 7 then // 0.0.0.0
if checkproxy(' http://www.google.com ') then
begin
antifreeze := TIdAntiFreeze.Create(nil);
httpcon := TIdHTTP.create;
httpcon.ProxyParams.BasicAuthentication:=true;
httpcon.ProxyParams.ProxyPassword:=SettingsForm.edtProxyPass.Text;
httpcon.ProxyParams.ProxyPort:=strtoint(SettingsForm.edtProxyPort.Text);
httpcon.ProxyParams.ProxyServer:=SettingsForm.edtProxyServer.Text;
httpcon.ProxyParams.ProxyUsername:=SettingsForm.edtProxyUserName.Text;
end
else
begin
showmessage('Proxy Server Not Working.. Attempting to bypass the Proxy');
antifreeze := TIdAntiFreeze.Create(nil);
httpcon := TIdHTTP.create;
//httpcon.Request.ProxyConnection:='';
//httpcon.ProxyParams.BasicAuthentication:=false;
//httpcon.ProxyParams.ProxyPassword:='';
//httpcon.ProxyParams.ProxyPort:=0;
//httpcon.ProxyParams.ProxyServer:='';
//httpcon.ProxyParams.ProxyUsername:='';
end;
httpcon.HandleRedirects := true;
antifreeze.Active := true;
HttpCon.Get(sURL,sstream);
result := utf8towidestring(sstream.DataString);
except
httpcon.Disconnect;
end;
antifreeze.Active := false;
freeandnil(httpcon);
freeandnil(antifreeze);
freeandnil(sstream);
end;
function TregForm.checkproxy(sURL : ansistring) : boolean; var //sstream : Tstringstream; httpcon : TIdHTTP; antifreeze : TIdAntiFreeze; begin result := true; try antifreeze := TIdAntiFreeze.Create(nil); httpcon := TIdHTTP.create; //sstream := tstringstream.Create(''); httpcon.ProxyParams.BasicAuthentication:=true; httpcon.ProxyParams.ProxyPassword:=SettingsForm.edtProxyPass.Text; httpcon.ProxyParams.ProxyPort:=strtoint(SettingsForm.edtProxyPort.Text); httpcon.ProxyParams.ProxyServer:=SettingsForm.edtProxyServer.Text; httpcon.ProxyParams.ProxyUsername:=SettingsForm.edtProxyUserName.Text;
httpcon.HandleRedirects := true;
antifreeze.Active := true;
HttpCon.Request.ProxyConnection:=SettingsForm.edtProxyServer.Text;
HttpCon.head(sURL);
httpCon.Disconnect;
除了 在E:EIdException就开始 结果:= FALSE; 结束; 关于E:例外开始 // showmessage('外部错误:'+#13#10 + E.Message); showmessage('Proxy Settings Error'); 结果:= false; 结束; 结束; antifreeze.Active:= false; freeandnil(httpcon); freeandnil(防冻液); // freeandnil(sstream); 结束;
错误消息:E001B844A模块key.exe中的异常AccessViolation。 模块'key.exe'中地址为005B844A的访问冲突。读地址00000000
你是什么意思,当你说“它崩溃”? – 2010-01-18 06:21:30
我得到一个运行时错误,并且程序崩溃了,并且想要将崩溃数据发送到微软。 – Brad 2010-01-18 07:02:36
我剪切/粘贴的实际代码...当我使用调试器运行程序关闭它立即弹出与请告诉微软有关此问题的消息。然后提供错误信息。当我使用调试器运行时,会给我一个中断通知,但不会导致导致问题的代码行。 – Brad 2010-01-18 07:39:31