[fpc-pascal] Case statement for class introspection
Ryan Joseph
genericptr at gmail.com
Sat Jan 15 02:28:38 CET 2022
I saw a new syntax in Swift which I thought was clever and fits a pattern I've seen before. Basically it's a case statement for class types which lets you branch depending on which class type the class instance is at run time.
I wonder if this could be implemented in FPC? The syntax would be kind of clumsy though since you can't declare scoped variables in Pascal so you would need to do lots of casts but it's still cleaner than the equivalent code as if statements.
=====================
case monster of
TZenChan:
TZenChan(monster).DoThis;
TPulPul:
TPulPul(monster).DoThat;
otherwise
monster.DoSomething;
end;
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list