msd 5 Posted October 6 Hello, I have custom managed type for example: TvatIndividual = record DocumentNumber: string; TurnoverDate: TDate; PaymentDate: TDate; DocumentType: string; Year: integer; TurnoverDescription: string; TurnoverAmount: Currency; end; I need to iterate over this record type and access its fields. For example, if I have 7 items, how can I retrieve the field names and their types using a loop in Delphi? Thanks in advance! Share this post Link to post
Kazantsev Alexey 24 Posted October 6 program Project1; {$APPTYPE CONSOLE} uses System.Rtti; type TvatIndividual = record DocumentNumber: string; TurnoverDate: TDate; PaymentDate: TDate; DocumentType: string; Year: integer; TurnoverDescription: string; TurnoverAmount: Currency; end; begin for var f in TRttiContext.Create.GetType(TypeInfo(TvatIndividual)).GetFields do WriteLn(f.ToString); ReadLn; end. 1 2 Share this post Link to post
dummzeuch 1505 Posted October 6 Just in case anybody else is wondering: This works since Delphi 2010 which was the version that first included the unit rtti. Older Delphi versions did not support RTTI for records. 1 Share this post Link to post