[fpc-pascal] Case statement for class introspection

Michael Van Canneyt michael at freepascal.org
Sun Jan 16 08:35:27 CET 2022



On Sun, 16 Jan 2022, Ryan Joseph via fpc-pascal wrote:

>
>
>> On Jan 16, 2022, at 9:21 AM, Ryan Joseph <genericptr at gmail.com> wrote:
>> 
>> There is a possibility for using "as" operator also though....
>
> oops I mean "is" operator. Not sure if these are technically different from ClassType = ClassType though...

They are.

No "is", because then the order of the label will start to matter, and that runs contrary
to the case statement's intent.

if you use 'is' then

case A of
   TPersistent: Writeln('TPersistent');
   TComponent : Writeln('TComponent');
end;

would always stop at TPersistent for every TComponent descendent, and that
is not what you want.

So to preserve the semantics of 'case' (order of labels does not matter), 
it must be an exact match.

Michael.


More information about the fpc-pascal mailing list