Delphi RTTI TVirtualMethodInterceptor.Create 不支持具有重载虚方法的class
Delphi RTTI TVirtualMethodInterceptor.Create doesn't support the class that has overload virtual method
我发现 TVirtualMethodInterceptor.Create 不支持具有重载虚方法的 class。
例如
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"。
有人可以帮助我吗?
出现此消息是因为您的 class 方法的某些参数未发出 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;
我发现 TVirtualMethodInterceptor.Create 不支持具有重载虚方法的 class。 例如
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"。 有人可以帮助我吗?
出现此消息是因为您的 class 方法的某些参数未发出 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;