Delegating to a Class Type Property

If the delegate property is of a class type, that class and its ancestors are searched for methods implementing the specified interface before the enclosing class and its ancestors are searched. Thus it is possible to implement some methods in the class specified by the property, and others in the class where the property is declared. Method resolution clauses can be used in the usual way to resolve ambiguities or specify a particular method. An interface cannot be implemented by more than one class-type property. For example, type

IMyInterface = interface procedure P1; procedure P2; end;

TMylmplClass = class procedure P1; procedure P2; end;

TMyClass = class(TInterfacedObject, IMyInterface) FMylmplClass: TMyImplClass;

property MyImplClass: TMyImplClass read FMyImplClass implements IMyInterface; procedure IMyInterface.P1 = MyP1; procedure MyP1; end;

procedure TMyImplClass.P1;

procedure TMyImplClass.P2;

procedure TMyClass.MyPl;

MyClass: TMyClass; MyInterface: IMyInterface; begin

MyClass := TMyClass.Create;

  1. FMyImplClass := TMyImplClass.Create; MyInterface := MyClass;
  2. P1; // calls TMyClass.MyPl; MyInterface.P2; // calls TImplClass.P2; end;
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment