Re: [fpc-pascal] Traits Proposal
> On Feb 18, 2021, at 11:30 PM, Sven Barth wrote: > > The only thing that will not work and which will continue not to work is that > m_circle.Draw will not be called if you access the TMyShape through a > TShape.Draw call. For that one needs to use an explicit declaration: > > === code begin === > > type > TMyShape = class(TShape, ICircle) > private > m_circle: TCircle; > public > procedure ICircle.Draw = Draw; > property Circle: TCircle read m_circle implements ICircle; > procedure Draw; override; > end; > > procedure TMyShape.Draw; > begin > m_circle.Draw; > end; > > === code end === So the method resolution doesn't actually change the VMT table of the class, just the interface? That's unfortunate because being able to affect the VMT by method resolution would open up a lot of possibilities for polymorphism using composition. Maybe writing wrapper functions is good enough for this. Not sure, I need to do some research into old code and explore things a bit more. I just realized another potential problem. If we use the "default" keyword that means there could be multiple "defaults" unless we limit the property to 1 per class, which would kind of defeat the purpose of the feature (like the issue we had with helpers and made multi-helpers for). Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Traits Proposal
Btw, here's point of reference for this other proposed syntax. https://github.com/genericptr/freepascal/wiki/Default-Implements-Property Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Traits Proposal
Ryan Joseph via fpc-pascal schrieb am Fr., 19. Feb. 2021, 17:32: > Btw, here's point of reference for this other proposed syntax. > > https://github.com/genericptr/freepascal/wiki/Default-Implements-Property Your example is not quite correct and it's also not really complete: if a class implements an interface there *must* be a parent class mentioned (at least TObject). Also your example should demonstrate that one can call TMyShape.Draw without having to retrieve the interface (after all that's the point of the interface property). Additionally support for raw interfaces (aka Corba) should be added for interface delegation if it isn't already supported. (Otherwise your TMyShape either needs to inherit from e.g. TInterfacedObject or one of the involved types needs to implement the methods of IInterface. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Traits Proposal
> On Feb 19, 2021, at 11:01 AM, Sven Barth via fpc-pascal > wrote: > > Your example is not quite correct and it's also not really complete: if a > class implements an interface there *must* be a parent class mentioned (at > least TObject). Also your example should demonstrate that one can call > TMyShape.Draw without having to retrieve the interface (after all that's the > point of the interface property). > TObject is always the root class I thought? Why is it different here? > Additionally support for raw interfaces (aka Corba) should be added for > interface delegation if it isn't already supported. (Otherwise your TMyShape > either needs to inherit from e.g. TInterfacedObject or one of the involved > types needs to implement the methods of IInterface. > They work already fortunately. Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Traits Proposal
Op 2021-02-19 om 16:50 schr So the method resolution doesn't actually change the VMT table of the class, just the interface? See it like this: An interface is a fragment of VMT. All methods of the interface are there in order. If implemented right, it is like a pointer into the implementing classes' VMT table. The IVT is a mapping of interface identifiers (in COM terms, GUIDS) mapped to the offset into the VMT they apply too. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Traits Proposal
Am 19.02.2021 um 20:37 schrieb Ryan Joseph via fpc-pascal: On Feb 19, 2021, at 11:01 AM, Sven Barth via fpc-pascal wrote: Your example is not quite correct and it's also not really complete: if a class implements an interface there *must* be a parent class mentioned (at least TObject). Also your example should demonstrate that one can call TMyShape.Draw without having to retrieve the interface (after all that's the point of the interface property). TObject is always the root class I thought? Why is it different here? TObject *is* always the root, but the first entry of the inheritance list of a class *must* be a class as well. Additionally support for raw interfaces (aka Corba) should be added for interface delegation if it isn't already supported. (Otherwise your TMyShape either needs to inherit from e.g. TInterfacedObject or one of the involved types needs to implement the methods of IInterface. They work already fortunately. Good. :) Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Traits Proposal
> On Feb 19, 2021, at 3:14 PM, Sven Barth via fpc-pascal > wrote: > > TObject *is* always the root, but the first entry of the inheritance list of > a class *must* be a class as well. I'm testing interface delegation now in ObjFPC mode and I don't see that including TObject is required. Regards, Ryan Joseph ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Traits Proposal
On Fri, 19 Feb 2021 15:37:03 -0700 Ryan Joseph via fpc-pascal wrote: > > On Feb 19, 2021, at 3:14 PM, Sven Barth via fpc-pascal > > wrote: > > > > TObject *is* always the root, but the first entry of the > > inheritance list of a class *must* be a class as well. > > I'm testing interface delegation now in ObjFPC mode and I don't see > that including TObject is required. In Delphi the first must be a class. FPC allows to omit the class and uses TObject as default. Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal