I'm trying to get a const filled with the offset of a field in a record. I can get it to work for top fields, but not for nested fields
Silly question, but are things being made worse by the fact that the main and subfields have a common name?
I'd suggest that you might do better if you broke the nested field out as its own type, computed the offsets of its fields separately, and then added those to the main field offset as appropriate.
That would leave the problem of variant records, which (with care) would probably be amenable to the same treatment, otherwise obviously note PascalDragon's comments.
In all cases, I'd be inclined to have assertions somewhere to make sure that integer (etc.) actually does have the size expected. I'd also be inclined to put a comment wherever the non-obvious @PSomething(nil)^ construct is used, so that anybody reading the code understands that it's simulating a variable at address zero... and I don't know whether this is necessary but it might be worth having an explicit check that PtrUInt(nil) is zero since while I don't think this applies to FPC I've seen platforms where it didn't hold.
MarkMLl