Re: [fpc-pascal] Explicit Interface implementation and inheritance

2021-08-14 Thread Jean SUZINEAU via fpc-pascal

Ooops, may be I hit reply too fast.

It looks like when you write " TObjB = class(TObjA, IBBB)" you just 
implement IAAA twice.

If you comment out IBBB
  TImpB = class(TImpA{, IBBB})
  public
    procedure CallOfB;
    //procedure IBBB.MethodB = CallOfB;
  end;

then the "No matching implementation" error disappears, the inherited 
implementation is well taken in account.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Explicit Interface implementation and inheritance

2021-08-14 Thread Jean SUZINEAU via fpc-pascal

Le 15/08/2021 à 00:43, Dmitry Boyarintsev via fpc-pascal a écrit :
Why is interface implementation not inherited, if explicit 
implementation is used.


I guess this is because you can implement an interface through 
delegation too:


https://www.freepascal.org/docs-html/ref/refse48.html

type
  IMyInterface = interface
procedure P1;
  end;

  TMyClass = class(TInterfacedObject, IMyInterface)
  private
FMyInterface: IMyInterface; // interface type
  public
property MyInterface: IMyInterface
   read FMyInterface implements IMyInterface;
  end;


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Explicit Interface implementation and inheritance

2021-08-14 Thread Dmitry Boyarintsev via fpc-pascal
Hello,

Why is interface implementation not inherited, if explicit implementation
is used.

Example.

Here are interfaces:
  IAAA = interface
procedure MethodA;
  end;
  IBBB = interface(IAAA)
procedure MethodB;
  end;

Interface IBBB inherits from IAAA

Here's an implicit interface implementation:

  TObjA = class(TInterfacedObject, IAAA)
procedure MethodA;
  end;

  TObjB = class(TObjA, IBBB)
procedure MethodB;
  end;

Class TObjB inherits from TObjA. Where TObjA implements IAAA.
And so TObjB only needs to implement MethodB, and MethodA is implicitly
mapped for the interface method.

Here's an explicit interface implementation:

  TImpA = class(TInterfacedObject, IAAA)
  public
procedure CallOfA; virtual;
procedure IAAA.MethodA = CAllOfA;
  end;

  // compiler error. No matching implementation for interface method
"MethodA"; found
  TImpB = class(TImpA, IBBB)
  public
procedure CallOfB;
procedure IBBB.MethodB = CallOfB;
  end;

Why is it happening? TImpB inherites from TImpA. In TImpA the MethodA is
implemented by "CallOfA".

Is it a requirement to map all the methods of implemented interfaces? (no
matter if they were implemented in parent classes).

thanks,
Dmitry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal