[fpc-devel] case is

Hairy Pixels genericptr at gmail.com
Thu Mar 24 02:34:49 CET 2022



> On Mar 24, 2022, at 8:14 AM, Hairy Pixels <genericptr at gmail.com> wrote:
> 
> Search for "Case statement for class introspection” and you see can the little discussion we had about a potential speed up and why it wasn’t viable so for now it’s just using a if-else statement with A.ClassType = B.ClassType comparisons. It’s just syntactic sugar at this point but it was trivial to implement and I think it’s much nicer to work with so for me that’s a total win.
> 

I just realized one thing worth changing. So this is how I implemented it, essentially it’s a case-of-ClassType, which means the compiler now has: case of ordinal, case of string and case of classType.

c := TInterfacedObject.Create;

  case c of
    TObject:            result := 1;
    TInterfacedObject:  result := 2;
    TAggregatedObject:  result := 3;
    otherwise           result := 4;
  end;

But because I did an implicit “c.ClassType” it wouldn’t be possible to use “nil” as a case. Maybe not a big deal because you can capture nil in “otherwise” but it’s something to consider.

Regards,
	Ryan Joseph



More information about the fpc-devel mailing list