Quick start manual
Object interfaces
10-7
Implementing interfaces
Implementing interfaces by delegation
The implements directive allows you to delegate implementation of an interface to a
property in the implementing class. For example,
property MyInterface: IMyInterface read FMyInterface implements IMyInterface;
declares a property called MyInterface that implements the interface IMyInterface.
The implements directive must be the last specifier in the property declaration and
can list more than one interface, separated by commas. The delegate property
• must be of a class or interface type.
• cannot be an array property or have an index specifier.
•must have a read specifier. If the property uses a read method, that method must
use the default register calling convention and cannot be dynamic (though it can
be virtual) or specify the message directive.
Note
The class you use to implement the delegated interface should derive from
TAggregatedObject.
Delegating to an interface-type property
If the delegate property is of an interface type, that interface, or an interface from
which it derives, must occur in the ancestor list of the class where the property is
declared. The delegate property must return an object whose class completely
implements the interface specified by the implements directive, and which does so
without method resolution clauses. For example,
type
IMyInterface = interface
procedure P1;
procedure P2;
end;
TMyClass = class(TObject, IMyInterface)
FMyInterface: IMyInterface;
property MyInterface: IMyInterface read FMyInterface implements IMyInterface;
end;
var
MyClass: TMyClass;
MyInterface: IMyInterface;
begin
MyClass := TMyClass.Create;
MyClass.FMyInterface := ... // some object whose class implements IMyInterface
MyInterface := MyClass;
MyInterface.P1;
end;