Am 21.03.2020 um 08:47 schrieb Ryan Joseph via fpc-pascal:

On Mar 21, 2020, at 9:39 AM, Ryan Joseph via fpc-pascal 
<fpc-pascal@lists.freepascal.org> wrote:

I'm going to loop through the fields of the record and get the size of each
field so I can serialize the record. Am I not on the right track?
No answers on this so I'm thinking maybe I need to use TManagedField^.FldOffset 
to get the information I need about the field size. Is that correct way to get 
the field size using record RTTI?

For the primitve types you need to know the sizes at compile time (e.g. SizeOf(Word), SizeOf(LongInt), etc.) and check what type the field has using the field list in the record's RTTI. You also have to keep in mind that some types are grouped. E.g. tkInteger is for all integer types that are smaller than 64-bit. The real type is then available as TTypeData.OrdType and you need to handle that size accordingly. For structured types like records the size is contained in the RTTI. The FldOffset field is important to get the correct offset of a field, because padding might be involved depending on the platform (except if your record is "packed").

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to