7
我在使用rtti獲取有關泛型類型的類字段的信息時遇到了問題。經過相當一些googleing後,我在QC找到了一個描述該問題的條目。我的問題是,如果有人知道解決方法,或者這是固定的Delphi XE2。以下是來自QC的源代碼片段,用於重現該錯誤。Rtti不適用於用作類字段的泛型類型
program Generics;
{$APPTYPE CONSOLE}
uses
Generics.Collections, Rtti, SysUtils;
type
TIntList = TList<Integer>;
TRecContainer = record
FList: TIntList;
end;
TObjContainer = class
FList: TIntList;
end;
var
ctx: TRttiContext;
f: TRttiField;
begin
ctx := TRttiContext.Create;
try
for f in ctx.GetType(TypeInfo(TRecContainer)).GetFields do
if f.FieldType <> nil then
writeln(f.FieldType.Name)
else
writeln('f.FieldType = nil');
for f in ctx.GetType(TypeInfo(TObjContainer)).GetFields do
if f.FieldType <> nil then
writeln(f.FieldType.Name)
else
writeln('f.FieldType = nil');
finally
ctx.Free;
readln;
end;
end.
好了,我可以證實它不是在XE2工作。 –