[fpc-pascal] Case statement for class introspection

Sven Barth pascaldragon at googlemail.com
Sun Jan 16 17:15:45 CET 2022


Am 16.01.2022 um 15:25 schrieb Ryan Joseph via fpc-pascal:
>
>> On Jan 16, 2022, at 9:01 PM, Ryan Joseph <genericptr at gmail.com> wrote:
>>
>>   case PtrUInt(o.ClassType) of
>>     4500656856: writeln('TObject');
>>   end;
> I may have spoken too soon and without thinking the through clearly (it's getting late here!). For this to work we would need a unique ID in the RTTI, right? I don't think that exists so unless it does we need to do equality comparisons for each case.

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.

Regards,
Sven


More information about the fpc-pascal mailing list