Andersen Chang
Andersen Chang

Reputation: 45

Delphi RTTI TVirtualMethodInterceptor.Create doesn't support the class that has overload virtual method

I found TVirtualMethodInterceptor.Create doesn't support the class that has overload virtual method. For examples

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;

While executed TVirtualMethodInterceptor.Create(), it will raise exception "Insufficient RTTI available to support this operation". Anybody could help me ?

Upvotes: 2

Views: 810

Answers (1)

RRUZ
RRUZ

Reputation: 136431

This message is raised because some parameters of the methods of your class is not emitting RTTI information. This is the case of this method

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

replace with this one

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

Upvotes: 5

Related Questions