Search code examples
delphiproxydelphi-xe

Operator not applicable to this operand type+Socks+SSL


Trying some proxy stuff, i get this error : Operator not applicable to this operand type , i used visual component before and it was good, now i changed the code i get this..code below.

  var 
    lHTTP: TIdHTTP;
    IdSSL: TIdSSLIOHandlerSocketOpenSSL;
    Socks : TIdSocksInfo;
    Host, Port : String;
  begin
    try
    lHTTP := TIdHTTP.Create(nil);
    IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(lHTTP);


      lHTTp.ReadTimeout := 60000;

      IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];

      IdSSL.SSLOptions.Mode := sslmClient;
      IdSSL.TransparentProxy := Socks.Create(lHTTP);

      (IdSSL.TransparentProxy as Socks).Port := Port.ToInteger(); //Error
      (IdSSL.TransparentProxy as Socks).Host := Host;            //Error

      (IdSSL.TransparentProxy as Socks).Version := svSocks5;  //Error

      lHTTP.IOHandler := IdSSL;
      lHTTP.HandleRedirects := True;

   end;

Solution

  • Your typecasts are wrong, that is why you are getting errors. You need to cast to a type, not to a variable name:

    (IdSSL.TransparentProxy as TIdSocksInfo).Port := Port.ToInteger;
    (IdSSL.TransparentProxy as TIdSocksInfo).Host := Host;
    (IdSSL.TransparentProxy as TIdSocksInfo).Version := svSocks5;
    

    A better option is to use the variable you have declared, and don't use typecasts at all:

    Socks := Socks.Create(lHTTP);
    Socks.Port := Port.ToInteger;
    Socks.Host := Host;
    Socks.Version := svSocks5;
    IdSSL.TransparentProxy := Socks;