我发现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()时,它会引发异常"可用的RTTI不足以支持此操作"。 有人可以帮帮我吗?
答案 0 :(得分:5)
引发此消息是因为类的方法的某些参数未发出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;