In Delphi 2007, I use one class to implement one of the supported interfaces of the second class. It works. Help Delphi reports:
By default, using the keyword delegate implements the entire interface of the methods. However, you can use method resolution clauses or declare methods in your class that implement some of the interface methods to override this default behavior.
However, when I declare a method in my second class that has the corresponding signature of one of the interface methods, it does not receive the call.
Interestingly, this is because I access the class through another interface when I create it.
The following is a test program demonstrating my problem:
program Project1; {$APPTYPE CONSOLE} type IInterface1 = interface ['{15400E71-A39B-4503-BE58-B6D19409CF90}'] procedure AProc; end; IInterface2 = interface ['{1E41CDBF-3C80-4E3E-8F27-CB18718E8FA3}'] end; TDelegate = class(TObject) protected procedure AProc; end; TMyClass = class(TInterfacedObject, IInterface1, IInterface2) strict private FDelegate: TDelegate; property Delegate: TDelegate read FDelegate implements IInterface1; public constructor Create; destructor Destroy; override; procedure AProc; end; procedure TDelegate.AProc; begin writeln('TClassDelegate.AProc'); end; constructor TMyClass.Create; begin inherited; FDelegate := TDelegate.Create; end; destructor TMyClass.Destroy; begin FDelegate.Free; inherited; end; procedure TMyClass.AProc; begin writeln('TMyClass.AProc'); end; var MyObj : IInterface2; begin MyObj := TMyClass.Create; (MyObj as IInterface1).AProc; end.
When I run this, I get the output:
TClassDelegate.AProc
I want to:
TMyClass.AProc
Any help was appreciated.
source share