> On Mar 24, 2022, at 8:14 AM, Hairy Pixels <generic...@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

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

Reply via email to