I am having problems using rtti to get information about class fields of a generic type. After quite a lot of googleing, I found a QC entry describing the problem. My question is if anyone knows a workaround, or if this is fixed by Delphi XE2. Below is a snippet of source code from QC to reproduce the error.
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.
iamjoosy
source share