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



我发现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 不足,无法支持此操作"。有人可以帮助我吗?

引发此消息是因为类的方法的某些参数未发出 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; 

最新更新