Rtti does not work with generic types that are used as class fields

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. 
+7
source share
1 answer

Unfortunately, this error is still present in Delphi XE2, as a workaround you can declare a TIntList type as follows

 TIntList = class(TList<Integer>); 
+8
source

All Articles