[fpc-pascal] Case statement for class introspection
Ryan Joseph
genericptr at gmail.com
Sun Jan 16 14:18:15 CET 2022
I had some fun today on my day off and managed to actually implement this based on the if-statement based string case labels. Is the compiler team interested in this feature? I think it's a clearly useful addition to OOP and an appropriate new use of the case statement.
https://gitlab.com/genericptr/free-pascal/-/commits/case_label_classref
Here's an example of what I did. To keep it simple you use "ClassType" to branch off of possible class types.
========================
o := TInterfacedObject.Create;
case o.ClassType of
TObject: writeln('TObject');
TInterfacedObject: writeln('TInterfacedObject');
TAggregatedObject: writeln('TAggregatedObject');
otherwise
writeln('OTHER: ',o.ClassName);
end;
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list