[fpc-pascal] Is it posible to implement more than one interface in a class defination?

Sven Barth pascaldragon at googlemail.com
Sun Nov 14 18:11:48 CET 2010


On 14.11.2010 17:49, Graeme Geldenhuys wrote:
>     * incomplete delegation (non existent in FPC 2.4.2)

I haven't used this for quite a long time, so I can't test it just 
now... what are you missing?

>     * No name resolution (function aliases) of conflicting interfaces

Ehhh... the following code compiles with 2.4.2 and even 2.4.0:

==== source begin ====

program interfacetest;

{$mode objfpc}

uses
   SysUtils;

type
   IMyInterface = interface
     procedure Foo;
   end;

   TMyInterfacedObject = class(TInterfacedObject, IMyInterface)
   public
     procedure IMyInterface.Foo = Bar;
     procedure Bar;
     procedure Foo;
   end;

procedure TMyInterfacedObject.Bar;
begin
   Writeln('Bar');
end;

procedure TMyInterfacedObject.Foo;
begin
   Writeln('Foo');
end;

var
   t: TMyInterfacedObject;
   i: IMyInterface;
begin
   t := TMyInterfacedObject.Create;
   try
     i := t;
     t.Foo;
     i.Foo;
   finally
     t.Free;
   end;
end.

==== source end ====

Output is:

==== output begin ====

Foo
Bar
An unhandled exception occurred at $08056B71 :
EInvalidPointer : Invalid pointer operation
   $08056B71

==== output end ====

(I don't know currently where exactly that EInvalidPointer comes 
from.... even a "t.AddRef" doesn't solve this...)

Regards,
Sven



More information about the fpc-pascal mailing list