Important Interfaces information omitted from the ref documentation
Original Reporter info from Mantis: ggeldenhuys
-
Reporter name: Graeme Geldenhuys
Original Reporter info from Mantis: ggeldenhuys
- Reporter name: Graeme Geldenhuys
Description:
I did some recent tests with Interfaces under FPC 2.6.0 and 2.6.2-rc. The following is important information that I think should be included in the Interfaces chapter.
- Delegation to interface-type properties is fully supported.
This works in both COM and CORBA style interfaces.
eg:
{$interfaces corba}
type
IMyInterface = interface
procedure P1;
end;
TDelegateClass = class(TObject) // note: no interface specified
private
procedure P1;
end;
TMyClass = class(TInterfacedObject, IMyInterface)
private
FMyInterface: IMyInterface; // interface type
property MyInterface: IMyInterface read FMyInterface implements IMyInterface;
end;
- Delegation to class-type properties is supported, but it requires the delegate class to implement the interface (this requirement is absent in Delphi).
eg:
{$interfaces corba}
type
IMyInterface = interface
procedure P1;
end;
// NOTE: Interface must be specified here
TDelegateClass = class(TObject, IMyInterface)
private
procedure P1;
end;
TMyClass = class(TInterfacedObject, IMyInterface)
private
FMyInterface: TDelegateClass; // class type
property MyInterface: TDelegateClass read FMyInterface implements IMyInterface;
end;
- Method resolution also works, but it is mutually exclusive with delegation.
eg:
{$interfaces corba}
type
IMyInterface = interface
procedure P1;
end;
// This class my not use interface delegation at all
TMyClass = class(TInterfacedObject, IMyInterface)
private
procedure IMyInterface.P1 = MyP1;
procedure MyP1;
end;
Mantis conversion info:
- Mantis ID: 23414
- OS: Linux OpenSUSE
- OS Build: 12.2
- Platform: x86_64
- Fixed in version: 2.6.2
- Fixed in revision: 957 (#ff13209d)
- Target version: 2.6.2