Hi Ryan,

It's possible. Just change your declaration of `c`:

var c: TBase;

It still prints TMyClass at the end.

Of course, you're only going to have access to methods that are declared in
TBase.
You can also approach this sort of thing with interfaces...

-Michal  ( http://tangentstorm.com/ )


On Tue, Mar 24, 2020 at 4:08 AM Ryan Joseph via fpc-pascal <
fpc-pascal@lists.freepascal.org> wrote:

> Free Pascal - General mailing list wrote
> > Is it possible to achieve this dynamically without resorting to type
> > casting? It feels like classes should have a builtin type for each class,
> > like TClassType, which similar to TObject.ClassType but is a compile time
> > type.
>
> I didn't think enough before sending this because this clearly isn't a
> compile time issue. Currently this probably isn't possible unless there is
> an "AnyClass" type or something like that. Not sure if that exists in
> Pascal
> but methinks not.
>
>
>
> -----
> Regards,
>         Ryan Joseph
> --
> Sent from: http://free-pascal-general.1045716.n5.nabble.com/
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to