哪里覆盖了indy的TidStack类的虚方法?(0分)

  • 主题发起人 主题发起人 linuxping
  • 开始时间 开始时间
L

linuxping

Unregistered / Unconfirmed
GUEST, unregistred user!
为了得到本机的IP地址,我只要引用IdStack单元,然后使用
uses IdStack;
var IP:String;
begin
IP:=Gstack.LocalAddress;//Gstack是IdStack单元中预定义的TIdstack类型;
end;
然后我到Idstack单元查看它是怎样具体得到本机IP地址的代码,发现:
TIdStack = class
protected
FLocalAddress: string;
....
.....
function WSGetLocalAddress: string; virtual; abstract;
.....
.....
.....
public
.....
.....
.....
property LocalAddress: string read WSGetLocalAddress;
end;
var
GStack: TIdStack = nil;
我想问的是WSGetLocalAddress函数是抽象函数,WSGetLocalAddress在哪里被覆盖了?我一直都没有找到...没有一个类从它继承而来...?????
 
IdStack.pas
TIdStack = class(TObject)
protected
procedure PopulateLocalAddresses; virtual; abstract;
function GetLocalAddress: string; virtual; abstract;
function GetLocalAddresses: TIdStrings; virtual; abstract;
public
property LocalAddress: string read GetLocalAddress;
property LocalAddresses: TIdStrings read GetLocalAddresses;
end;
initialization
GStackClass :=
{$IFDEF LINUX} TIdStackLinux; {$ENDIF}
[red]{$IFDEF MSWINDOWS} TIdStackWindows; {$ENDIF}[/red]
{$IFDEF DOTNET} TIdStackDotNet; {$ENDIF}
GStackCriticalSection := TIdCriticalSection.Create;
finalization
Sys.FreeAndNil(GStackCriticalSection);
end.
注意红色的那行

function TIdStackWindows.GetLocalAddresses: TIdStrings;
begin
if FLocalAddresses = nil then
begin
FLocalAddresses := TIdStringList.Create;
end;
PopulateLocalAddresses;
Result := FLocalAddresses;
end;

procedure TIdStackWindows.PopulateLocalAddresses;
type
TaPInAddr = Array[0..250] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
i: integer;
AHost: PHostEnt;
PAdrPtr: PaPInAddr;
begin
FLocalAddresses.Clear ;
AHost := GetHostByName(PChar(HostName));
if AHost = nil then begin
CheckForSocketError(SOCKET_ERROR);
end else begin
PAdrPtr := PAPInAddr(AHost^.h_address_list);
i := 0;
while PAdrPtr^ <> nil do begin

FLocalAddresses.Add(TranslateTInAddrToString(PAdrPtr^^,Id_IPv4)); //BGO FIX
Inc(I);
end;
end;
end;

我用的是Indy10,代码和楼主的有点不一样,但是楼主可以根据这个思路自己寻找实现代码。
 
谢谢!
indy9里根本没有你那几行~initialization部分也没有~
 
接受答案了.
 
后退
顶部