> On Jan 15, 2022, at 3:24 PM, Michael Van Canneyt via fpc-pascal 
> <fpc-pascal@lists.freepascal.org> wrote:
> 
> I don't see how an inline variable helps with the casting mess. You'll
> always need a cast.
> 
> What I do is Var
>  MyInstance : TObject;
>  MyNeededClass : TMyNeededClass absolute myInstance:

Yes that's the best option.

Anyways, the case statement in FPC allows for strings which basically fold down 
into an if-else statement for comparing strings and this same logic could be 
expanded for class types. Seems like a smart extension to add but does the 
compiler team support this?

Something like this:

  case o.ClassType of
    TObject: writeln('TObject');
    TInterfacedObject: writeln('TInterfacedObject');
  end;

Converts to:

  if o.ClassType = TObject then
    writeln('TObject')
  else if o.ClassType = TInterfacedObject then
    writeln('TInterfacedObject');

There is a possibility for using "as" operator also though....

Regards,
        Ryan Joseph

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

Reply via email to