<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ryan Joseph via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Mo., 17. Jan. 2022, 02:38:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Jan 16, 2022, at 11:15 PM, Sven Barth <<a href="mailto:pascaldragon@googlemail.com" target="_blank" rel="noreferrer">pascaldragon@googlemail.com</a>> wrote:<br>
> <br>
> The class type already is a unique "ID" for each class type when doing an equal comparison. You can essentially take the address of the VMT as the constant values that the loaded value is compared against.<br>
<br>
Does that look something like this then? and if so, this is better then doing the if-statement block, like string case statements?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">At least the compiler would be able to optimize it better. </div><div dir="auto"><br></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">
<br>
case PtrUInt(o.ClassType.ClassInfo) of<br>
PtrUInt(TObject.ClassInfo): writeln('TObject');<br>
end;<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">No, that is the RTTI. While that would work as well that is an additional indirection. So it would be more like:</div><div dir="auto"><br></div><div dir="auto">case PtrUInt(o.ClassType) of<br> PtrUInt(TObject): writeln('TObject');<br> end;<br></div><div dir="auto"><br></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">
<br>
Question then is how you get the VMT address as a constant at compile time.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I'll need to get back to you with that. </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>