[fpc-pascal] sizeof TTypeKind?
pascaldragon at googlemail.com
Sun Mar 22 09:33:07 CET 2020
Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
So., 22. März 2020, 07:28:
> > On Mar 21, 2020, at 10:15 PM, Sven Barth via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> > 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").
> ok, I guess I need to make a lookup table for tkInteger etc... or just
> take the field type names directly and map them myself.
You don't need to do a lookup table for all types. Retrieve the PTypeData
of the PTypeInfo (using GetTypeData) and check the OrdType if it's a
tkInteger. Based on that you map the size.
> Btw, I was thinking that the new custom attributes could be used to add
> RTTI to record fields but it appears to be limited to classes, and other
> class definitions. Is that correct?
For now that is correct as for everything else extended RTTI is required
(though to be more precise attributes can be used for all type
declarations, not only classes).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal