<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Hairy Pixels <<a href="mailto:genericptr@gmail.com">genericptr@gmail.com</a>> schrieb am Do., 6. Okt. 2022, 13:49:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Oct 6, 2022, at 12:45 PM, Sven Barth <<a href="mailto:pascaldragon@googlemail.com" target="_blank" rel="noreferrer">pascaldragon@googlemail.com</a>> wrote:<br>
> <br>
> Am 05.10.2022 um 14:16 schrieb Hairy Pixels via fpc-pascal:<br>
>> 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.<br>
> <br>
> 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*<br>
<br>
Oh so the problem is variant thinks it should try to manage memory for you? I tried doing:<br>
<br>
v: variant;<br>
begin<br>
v := GetMem(100);<br>
<br>
And that crashed also. I thought it would be ok to just hold the reference but not claim ownership over it.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Variants count as managed types and they can contain interface references and strings. If you use a custom type you can do as you please, but the internal types that can be assigned to a Variant *are* managed accordingly (if the types themselves are managed). </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>