Getting RTTI Failure Record Field Type for Static Arrays

I am trying to get the types for the record fields in order to create the correct match (as a general solution for any / almost any type of record). I can not find type information for static arrays:

TArrFieldTest = record a: string; b: array[0..3] of byte; end; procedure Test; var rttiContext: TRttiContext; rttiType: TRttiType; rttiFields: TArray<TRttiField>; begin rttiType := rttiContext.GetType(TypeInfo(TArrFieldTest)); rttiFields := rttiType.GetFields; Assert(rttiFields[0].FieldType<>nil); // it ok Assert(rttiFields[1].FieldType<>nil); // fail here! end; 

FieldType is zero for a static array of any type. Any ideas what is wrong here? Or maybe there is an easier way to create a comparer for the entries to be used with TArray / TDictionary, etc.?

+6
source share
1 answer

You need to declare a type in order to have RTTI. For instance:

 type TMyStaticArrayOfByte = array[0..3] of byte; TArrFieldTest = record a: string; b: TMyStaticArrayOfByte; end; 
+9
source

All Articles