Home > Net >  delphi rtti access array in record
delphi rtti access array in record

Time:05-20

I want to enumerate field information (name, type, …) of a record. RTTI delivers field name but type is null(nil)! How can I get this information?

Record:

 foo = record
  bar : array[0..5] of char;
 end;

Enumeration:

  for var f : TRttiField  in TRTTIContext.Create.GetType(TypeInfo(foo)).GetFields do
  begin
    OutputDebugString(PWideChar(f.Name   ' :: '   f.FieldType.ToString())); ///fieldtype is nil??!
  end;

CodePudding user response:

RTTI system works with predefined types (defining "on-the-fly" does not generate RTTI information), so declare types as

type
  TChar5Arr = array[0..5] of Char;

 foo = record
  bar : TChar5Arr;
 end;

And you will get some more info

name: bar
type: TChar5Arr
value: (array)    //is not retrieved using GetValue

CodePudding user response:

This means that the obtained TRttiContext can be used only to query for information about the declared types.

https://docwiki.embarcadero.com/RADStudio/Sydney/en/Querying_for_Type_Information

  • Related