gpt4 book ai didi

Delphi RTTI TVirtualMethodInterceptor.Create不支持具有重载虚方法的类

转载 作者:行者123 更新时间:2023-12-01 18:58:41 25 4
gpt4 key购买 nike

我发现TVirtualMethodInterceptor.Create不支持具有重载虚方法的类。举个例子

type
TLog = class
public
constructor Create();

procedure SaveLog(str: string); overload; virtual;
procedure SaveLog(str: string; Args: array of const); overload; virtual;
end;

constructor TLog.Create(str: string);
begin

end;

procedure TLog.SaveLog(str: string);
begin

end;

procedure TLog.SaveLog(str: string; Args: array of const);
begin

end;


procedure MyTest();
var
ttt: TLog;
vmi: TVirtualMethodInterceptor;

begin
ttt:=TLog.Create();
try
vmi:=TVirtualMethodInterceptor.Create(ttt.ClassType);
try
//
finally
vmi.Free();
end;
finally
ttt.Free();
end;
end;

执行TVirtualMethodInterceptor.Create()时,会引发异常“Insufficient RTTI available to support this operation”。有人可以帮助我吗?

最佳答案

出现此消息是因为类方法的某些参数未发出 RTTI 信息。这个方法就是这样的

 procedure SaveLog(str: string; Args: array of const); overload;  virtual; //array of const - doesn't emit rtti info.

替换为这个

type
TConst = array of TVarRec; //this type has rtti information
...
...
procedure SaveLog(str: string; Args: TConst); overload; virtual;

关于Delphi RTTI TVirtualMethodInterceptor.Create不支持具有重载虚方法的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27791370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com