[fpc-pascal] implements

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Wed Sep 6 09:50:51 CEST 2017


On 2017-09-05 05:05, Ryan Joseph wrote:
> That’s what I was looking for in terms of a practical use patterns
> for “implements properties”. I should have seen that at the start but
> I’m still hung up on how it’s implemented.


And to come back to your example in your first post:

  // your code
  TBaseClass = class (IHook)
  private
    m_hook: IHook;
  public
    constructor Create;
    property Hook: IHook read m_hook implements IHook;
  end;

What I do, and I suggest you try it too. Because you are using 
interfaces, the idea is that you use the Interface Reference variable 
only, never the property. To help you with that, move the "Hook" 
property from the Public section of the class, to the Private section.

  // with my changes
  TBaseClass = class (IHook)
  private
    m_hook: IHook;
    property Hook: IHook read m_hook implements IHook;
  public
    constructor Create;
  end;

There is NO need to make Hook public, because you can always get access 
to that functionality via the Supports() call and get a reference to IHook.


Regards,
   Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp



More information about the fpc-pascal mailing list