> On Oct 6, 2022, at 12:45 PM, Sven Barth <pascaldra...@googlemail.com> wrote:
> 
> 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*

Oh so the problem is variant thinks it should try to manage memory for you? I 
tried doing:

  v: variant;
begin
  v := GetMem(100);

And that crashed also. I thought it would be ok to just hold the reference but 
not claim ownership over it.

Regards,
        Ryan Joseph

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

Reply via email to