DelphiXE2 获取不到动态数组的RTTI信息,难道是Delphi的Bug??

tp机器猫 2012-11-01 02:50:57
type
TarrRec=TArray<TARecort>;

TTestClass=class(TInterfacedObject)
public
function TTest_Proxy.GetArr: TarrRec; // 这样写不能获得RTTI呢,
function TTest_Proxy.GetArr1: TArray<TARecort>; // 这样写就行,有没有人碰到过?
end;

T:=TRttiContext.Create.GetType(TTestClass);
method:=t.GetMethod('GetArr');

if Method.MethodKind=mkFunction then 取不到
...全文
256 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tp机器猫 2012-11-27
  • 打赏
  • 举报
回复
怎么发的贴子没有几个有回答正确,起码得挨点边呀。
BambooCaep 2012-11-27
  • 打赏
  • 举报
回复
不用tarray,直接定义为 Array of TtestRecort
tp机器猫 2012-11-02
  • 打赏
  • 举报
回复
XE2 泛型 相当于TarrRec=Array of TtestRecort;
RTTI信息取不到。

resultValue:=method.invoke()时报错。
而定义成 function TTest_Proxy.GetArr1: TArray<TARecort>; // 这样写就行,(也分两种情况行,如果写在同一个单元文件下也不行,不同单元文件下就可以。)
hsfzxjy 2012-11-01
  • 打赏
  • 举报
回复
TarrRec=TArray<TtestRecort>;好奇葩的写法,用D7的表示没见过
tp机器猫 2012-11-01
  • 打赏
  • 举报
回复
代码贴出来,
如下写的时候都取不到。
unit Unit5;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,System.Rtti, Vcl.StdCtrls, Vcl.Buttons,System.TypInfo
// ,test_intf
;
//
type

TtestRecort= packed record
a:integer;
b:string[20];
c:TDateTime;
end;

type
TarrRec=TArray<TtestRecort>;

ITest=interface
function Sum(A,B:integer):Integer;
function Sum1(A,B,c,d:integer):Integer;
function GetDate:TDateTime;
function GetARecord:TtestRecort;
function GetSomeStr(out str1:string;var Str2:string):string;
function GetArr1:TArray<TtestRecort>;
function GetArr:TarrRec;
procedure test1(out str:string);
end;

type
TForm5 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

type
TTestclass=class(TInterfacedObject,ITest)
public
function Sum(A,B:integer):Integer;
function Sum1(A,B,c,d:integer):Integer;
function GetDate:TDateTime;
function GetARecord:TtestRecort;
function GetSomeStr(out str1:string;var Str2:string):string;
function GetArr1:TArray<TtestRecort>;
function GetArr:TarrRec;
procedure test1(out str:string);
end;

var
Form5: TForm5;

implementation

{$R *.dfm}

{ TTestclass }


procedure TForm5.BitBtn1Click(Sender: TObject);
var
T:TRttiType;
m,m1,m2,m3:TRttiMethod;
begin
t:=TRttiContext.Create.GetType(TTestclass);
m:=t.GetMethod('GetArr');
m1:=t.GetMethod('GetArr1');
m2:=t.GetMethod('GetARecord');
m3:=t.GetMethod('GetDate');

if Assigned(m3) then
if m3.MethodKind=mkFunction then
OutputDebugString(PChar(m3.ToString));

if Assigned(m2) then
if m2.MethodKind=mkFunction then
OutputDebugString(PChar(m2.ToString));

if Assigned(m1) then
m1.GetParameters;
if m1.MethodKind=mkFunction then
OutputDebugString(PChar(m1.ToString));

if Assigned(m) then
m.GetParameters;
if m.MethodKind=mkFunction then
ShowMessage('取到');
end;

{ TTestclass }

function TTestclass.GetARecord: TtestRecort;
begin

end;

function TTestclass.GetArr: TarrRec;
begin

end;

function TTestclass.GetArr1: TArray<TtestRecort>;
begin

end;

function TTestclass.GetDate: TDateTime;
begin

end;

function TTestclass.GetSomeStr(out str1: string; var Str2: string): string;
begin

end;

function TTestclass.Sum(A, B: integer): Integer;
begin

end;

function TTestclass.Sum1(A, B, c, d: integer): Integer;
begin

end;

procedure TTestclass.test1(out str: string);
begin

end;

end.

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧