[fpc-pascal] implements

Ryan Joseph ryan at thealchemistguild.com
Sat Sep 2 06:03:27 CEST 2017


I think I asked this some years ago but I came across it again I just don’t get what the point of this is. There is an “implements” property but it seems like yet another half-baked feature from Delphi that wasn’t implemented completely or is broken. What’s the point of implementing an interface like this on TBaseClass if you need to access all the methods by using the property name (“hook” in this case) when you could just add an instance of THook in TBaseClass? It adds so much noise and clutter in the language and for what? The only reason it makes sense is if you could call “base.DoIt” and omit the .hook every time you’re typing but that was overlooked for some reason. Why??


type
  IHook = interface ['IHook']
    procedure DoIt;
  end;

type
	THook = class (IHook)
		procedure DoIt;
	end;

procedure THook.DoIt;
begin
	writeln(ClassName+' did it');
end;

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

constructor TBaseClass.Create;
begin
	m_hook := THook.Create;
end;


base: TBaseClass;

base := TBaseClass.Create;

base.DoIt; // CANT DO THIS
base.hook.DoIt; // MUST DO THIS


Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list