相关疑难解决方法(0)

TRttiMethod.Invoke函数在重载方法中不起作用?

我正在使用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)

delphi rtti delphi-xe2

6
推荐指数
1
解决办法
3731
查看次数

标签 统计

delphi ×1

delphi-xe2 ×1

rtti ×1