On 16-1-2022 14:18, Ryan Joseph via fpc-pascal wrote:
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;

What does it print in this case? I mean tobject matches, and tinterfacedobject too.

The most logic solution would be to only run the most specialized case?

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to