user3767493
user3767493

Reputation: 21

delphi rtti access array in record

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;

Upvotes: 1

Views: 289

Answers (2)

user3767493
user3767493

Reputation: 21

Per Delphi's documentation:

Querying for Type Information

In Delphi, type information is emitted only for types and not for global unit routines, constants, or variables. This means that the obtained TRttiContext can be used only to query for information about the declared types.

Upvotes: 0

MBo
MBo

Reputation: 80287

The RTTI system only works with predefined types. Defining field types "on-the-fly" does not generate RTTI information. So, declare the array type like this instead:

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

Upvotes: 3

Related Questions