运算符不适用于此操作数类型+Socks+SSL

Operator not applicable to this operand type+Socks+SSL

尝试一些代理的东西,我得到这个错误:Operator not applicable to this operand type,我以前使用过可视化组件,它很好,现在我改变了代码,我得到了这个..下面的代码。

  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;

您的类型转换有误,这就是您出现错误的原因。您需要转换为类型,而不是变量名:

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

更好的选择是使用您声明的变量,并且根本不使用类型转换:

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