Related to the question TVirtualMethodInterceptor.Create doesn't support the class that has overload virtual method. . After the modification of RRUZ's answer I got another problem. How should I call the second overload method "SaveLog(str: string; Args: array of TConst);" . As below codes
type
TConst = array of TVarRec;
TLog = class
public
constructor Create();
procedure SaveLog(str: string); overload; virtual;
procedure SaveLog(str: string; Args: TConst); overload; virtual;
end;
constructor TLog.Create(str: string);
begin
end;
procedure TLog.SaveLog(str: string);
begin
MessageBox(GetFocus(), PChar(str), 'Test Message', MB_OK);
end;
procedure TLog.SaveLog(str: string; Args: TConst);
var
buf: string;
begin
buf:=Format(str, Args);
SaveLog(buf);
end;
procedure MyTest(nID: Integer);
var
ttt: TLog;
vmi: TVirtualMethodInterceptor;
begin
ttt:=TLog.Create();
try
ttt.SaveLog('ID = %d', [nID]);
vmi:=TVirtualMethodInterceptor.Create(ttt.ClassType);
try
//
finally
vmi.Free();
end;
finally
ttt.Free();
end;
end;
The code " ttt.SaveLog('ID = %d', [nID]); " will get compiler error : E2250 There is no overloaded version of 'SaveLog' that can be called with these arguments . How should I do ?