Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your code above, if the "SettingsForm.edtProxyServer.text" is less than 7 chars, you will have a situation where you use AntiFreeze and HttpCon without creating them first.</p> <p>I experimented a little with your code, and tested this on my WinXP SP3 (D2010, Indy v10.5.5). This should be working code...</p> <pre><code>procedure TForm1.Button1Click(Sender: TObject); Var Resp : String; begin Resp := webSession('http://www.celarius.com'); if Length(Resp)&gt;0 then MessageDlg('Got the body ok',mtInformation,[mbOk],0); end; function TForm1.webSession(sURL : ansistring) : ansistring; var SStream : Tstringstream; HTTPCon : TIdHTTP; AntiFreeze : TIdAntiFreeze; begin Result := ''; if Length(SettingsForm.edtProxyServer.text) &gt;= 7 then // 0.0.0.0 Try SStream := NIL; AntiFreeze := NIL; HTTPCon := NIL; Try SStream := tstringstream.Create(''); { Create &amp; Set IdHTTP properties } HTTPCon := TIdHTTP.create; HTTPCon.HandleRedirects := true; { Check Proxy } if checkproxy('http://www.google.com') then Begin HTTPCon.ProxyParams.ProxyServer := SettingsForm.edtProxyServer.text; HTTPCon.ProxyParams.ProxyPort := StrToInt(SettingsForm.edtProxyPort.Text); HTTPCon.ProxyParams.BasicAuthentication := True; HTTPCon.ProxyParams.ProxyUsername := SettingsForm.edtProxyServer.Text; HTTPCon.ProxyParams.ProxyPassword := SettingsForm.edtProxyUserName.Text; End; { Create another AntiFreeze - only 1/app } AntiFreeze := TIdAntiFreeze.Create(nil); AntiFreeze.Active := true; HTTPCon.Get(sURL,SStream); Result := UTF8ToWideString(SStream.DataString); Finally If Assigned(HTTPCon) then FreeAndNil(HTTPCon); If Assigned(AntiFreeze) then FreeAndNil(AntiFreeze); If Assigned(SStream) then FreeAndNil(SStream); End; Except { Handle exceptions } On E:Exception do MessageDlg('Exception: '+E.Message,mtError, [mbOK], 0); End; end; function TForm1.checkproxy(sURL : ansistring) : boolean; var HTTPCon : TIdHTTP; AntiFreeze : TIdAntiFreeze; begin Result := False; Try { Inti vars } AntiFreeze := NIL; HTTPCon := NIL; Try { AntiFreeze } AntiFreeze := TIdAntiFreeze.Create(NIL); AntiFreeze.Active := true; { Create &amp; Set IdHTTP properties } HTTPCon := TIdHTTP.Create(NIL); HTTPCon.ProxyParams.ProxyServer := SettingsForm.edtProxyServer.text; HTTPCon.ProxyParams.ProxyPort := StrToInt(SettingsForm.edtProxyPort.Text); HTTPCon.ProxyParams.BasicAuthentication := True; HTTPCon.ProxyParams.ProxyUsername := SettingsForm.edtProxyServer.Text; HTTPCon.ProxyParams.ProxyPassword := SettingsForm.edtProxyUserName.Text; HTTPCon.HandleRedirects := true; HTTPCon.ConnectTimeout := 1000; HTTPCon.Request.Connection := 'close'; HTTPCon.Head(sURL); Finally { Cleanup } if Assigned(HTTPCon) then Begin { Return Success/Failure } Result := HTTPCon.ResponseCode = 200; If HTTPCon.Connected then HTTPCon.Disconnect; FreeAndNil(HTTPCon); End; if Assigned(AntiFreeze) then FreeAndNil(AntiFreeze); End; Except On E:EIdException do ; { Handle exceptions } On E:Exception do MessageDlg('Exception: '+E.Message,mtError, [mbOK], 0); End; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload