Re: [fpc-pascal] Chaining method calls

2020-03-25 Thread George Bakhtadze via fpc-pascal
Hi. You can have such ID if you will use generics: {$mode Delphi} type TBase = class public function AndThis: T; end; function TBase.AndThis: T; begin result := self as T; end; type TMyClass = class; TMyClass = class (TBase) end; var c: TMyClass; begin c :=

Re: [fpc-pascal] Chaining method calls

2020-03-24 Thread Ryan Joseph via fpc-pascal
> On Mar 24, 2020, at 8:39 PM, Michal Wallace via fpc-pascal > 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. >

Re: [fpc-pascal] Chaining method calls

2020-03-24 Thread Michal Wallace via fpc-pascal
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/ )

Re: [fpc-pascal] Chaining method calls

2020-03-24 Thread Ryan Joseph via fpc-pascal
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

[fpc-pascal] Chaining method calls

2020-03-23 Thread Ryan Joseph via fpc-pascal
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. = {$mode objfpc} program test; type TBase = class //