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;
Implementing interfaces
by delegation
如果一个委托属性是一个接口类型,那么该接口或从其派生的接口,必须出现在属性被声明的类的祖先列表中。委托属性必须返回一个对象,该对象所属的类完整地实现了由指示字implements指定的接口,并且没有方法决定子句。例如,
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 := ... //该对象所属的类实现了IMyInterface
MyInterface := MyClass;
MyInterface.P1;
end;