[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.


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');
      writeln('OTHER: ',o.ClassName);

	Ryan Joseph

More information about the fpc-pascal mailing list