Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework


Delegating to a Class-Type Property



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə232/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   228   229   230   231   232   233   234   235   ...   294
DelphiLanguageGuide

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;
TMyImplClass = class
 procedure P1;
 procedure P2;
end;
 TMyClass = class(TInterfacedObject, IMyInterface)
 FMyImplClass: TMyImplClass;
 property MyImplClass: TMyImplClass read FMyImplClass implements IMyInterface;
 procedure IMyInterface.P1 = MyP1;
 procedure MyP1;
end;
 procedure TMyImplClass.P1;
 .
    .
    .
 procedure TMyImplClass.P2;
 .   
    .
 . 
 procedure TMyClass.MyP1;
    .
    .
    .
var
 MyClass: TMyClass;
 MyInterface: IMyInterface;
begin
 MyClass := TMyClass.Create;
 MyClass.FMyImplClass := TMyImplClass.Create;
 MyInterface := MyClass;
 MyInterface.P1;    // calls TMyClass.MyP1;
 MyInterface.P2;    // calls TImplClass.P2;
end;
198



Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   228   229   230   231   232   233   234   235   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin