[fpc-pascal] Variants with classes and records
Sven Barth
pascaldragon at googlemail.com
Thu Oct 6 07:45:06 CEST 2022
Am 05.10.2022 um 14:16 schrieb Hairy Pixels via fpc-pascal:
> Is it possible to assign a class to a variant? I tried and get a crash. If not, why not? It’s just a pointer so I would expect it to work.
There is no field that would hold a class reference and no type value
that would differentiate it, thus the code handling variants would not
be able to finalize (aka free) a class correctly. You can of course
always use a custom type and handle that yourself. *shrugs*
> I also see a “varRecord” constant (in varianth.inc) which suggests you could assign a record to a variant but I get an error trying to do this, and honestly that makes sense so I’m curios what this constant is for.
The underlying TVarData record stems from Microsoft's COM (
https://learn.microsoft.com/en-us/windows/win32/api/oaidl/ns-oaidl-variant
) where there is also a record field, but neither Delphi nor FPC ever
supported that.
Regards,
Sven
More information about the fpc-pascal
mailing list