[fpc-pascal] Chaining method calls
Ryan Joseph
genericptr at gmail.com
Tue Mar 24 14:54:58 CET 2020
> On Mar 24, 2020, at 8:39 PM, Michal Wallace via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>
> 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...
>
True, but then we're stuck in a typecasting game where I need to cast "c" back to TMyClass. :) I probably brought this up years ago and forgot but Objective-C has an "id" type which is "can assign to any class type". It seems like something that would be standard for OOP but I don't recall ever seeing it in Pascal or C++.
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list