Embarcadero Delphi Implementing multiple interfaces


Example

Classes can implement more than one interface, as opposed to inheriting from more than one class (Multiple Inheritance) which isn't possible for Delphi classes. To achieve this, the name of all interfaces must be added comma-separated behind the base class.

Of course, the implementing class must also define the functions declared by each of the interfaces.

IInterface1 = interface
    ['{A2437023-7606-4551-8D5A-1709212254AF}']
    procedure Method1();
    function Method2(): Boolean;
end;

IInterface2 = interface
    ['{6C47FF48-3943-4B53-8D5D-537F4A0DEC0D}']
    procedure SetValue(const aValue: TObject);
    function  GetValue(): TObject;

    property Value: TObject read GetValue write SetValue;
end;

TImplementer = class(TInterfacedObject, IInterface1, IInterface2)
    // IInterface1
    procedure Method1();
    function Method2(): Boolean;

    // IInterface2
    procedure SetValue(const aValue: TObject);
    function  GetValue(): TObject

    property Value: TObject read GetValue write SetValue;
end;