2017-08-29 71 views

回答

4

TIdTelnet具有IPVersion屬性,但聲明爲protected,因此不能直接由用戶代碼訪問。爲了設置IPVersion,你可以聲明一個黑客類,如:

uses 
    .., IdStack, IdGlobal, .. 

type 
    TIdTelnetHack = class(TIdTelnet) 
    published 
    property IPVersion; //expose protected property 
    end; 

procedure TForm1.TelnetConnect(const aHost:String); 
var 
    aIPVersion: TIdIPVersion; 
begin 
    if not IdTelnet1.Connected then 
    begin //not connected. go connect 
    // check if ipv6 or ipv4 network, and support both, 
    try 
     GStack.ResolveHost(aHost, Id_IPv6); 
     aIPVersion := Id_IPV6; 
    except 
     GStack.ResolveHost(aHost, Id_IPv4); 
     aIPVersion := Id_IPV4; 
    end; 

    IdTelnet1.Host := aHost; 
    IdTelnet1.Port := 8090; 
    TIdTelnetHack(IdTelnet1).IPVersion := aIPVersion; //set to IPv4 or IPv6 

    IdTelnet1.Connect; 
    end; 
end; 

要測試IPv6網絡上你的應用程序,設置你的Mac作爲IPv6的接入點,因爲這裏說明:

Supporting IPv6 DNS64/NAT64 Networks

+2

您不需要明確發佈'IPVersion'屬性。後裔類繼承'protected'成員,並且類的聲明單元隱式訪問該類的'protected'成員。所以,在你的例子中'輸入TIdTelnetHack = class(TIdTelnet)''就足夠了。 –

+1

務必在Indy的問題跟蹤器中爲[此票證]投票(https://github.com/IndySockets/Indy/issues/164)。 –