我正在使用TRttiMethod.Invoke函数创建类的实例,但是当构造函数或方法重载时,rtti不会调用正确的方法.
我写了一个示例应用来说明我的问题.
program ProjectFoo;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Rtti,
System.SysUtils;
type
TFoo=class
public
constructor Create(Value : Integer);overload;
constructor Create(const Value : string);overload;
function Bar(value : integer) : Integer; overload;
function Bar(const value : string) : string; overload;
end;
{ TFoo }
constructor TFoo.Create(Value: Integer);
begin
Writeln(Value);
end;
function TFoo.Bar(value: integer): Integer;
begin
Writeln(Value);
Result:=value;
end;
function TFoo.Bar(const value: string): string;
begin
Writeln(Value);
Result:=value;
end;
constructor TFoo.Create(const Value: string);
begin
Writeln(Value);
end;
var
c : TRttiContext;
t : …Run Code Online (Sandbox Code Playgroud)