[fpc-devel] {$Interfaces Corba} and TInterfacedObject

Martin Schreiber fpmse at bluewin.ch
Fri Nov 30 11:58:51 CET 2007


On Friday 30 November 2007 11.22, Florian Klaempfl wrote:
> > I forgot to mention that the Delphi 'implements' keyword
>
> FPC supports this? Thought some bugs are known iirc.
>
Is the following from Delphi 7 help possible with FPC?
"
If the delegate property is of a class type, that class and its ancestors are 
searched for methods implementing the specified interface before the 
enclosing class and its ancestors are searched. Thus it is possible to 
implement some methods in the class specified by the property, and others in 
the class where the property is declared. Method resolution clauses can be 
used in the usual way to resolve ambiguities or specify a particular method. 
An interface cannot be implemented by more than one class-type property. For 
example,

type
  IMyInterface = interface
    procedure P1;
    procedure P2;
  end;
  TMyImplClass = class
    procedure P1;
    procedure P2;
  end;
  TMyClass = class(TInterfacedObject, IMyInterface)
    FMyImplClass: TMyImplClass;
    property MyImplClass: TMyImplClass read FMyImplClass implements 
IMyInterface;
    procedure IMyInterface.P1 = MyP1;
    procedure MyP1;

  end;
procedure TMyImplClass.P1;
  ...
procedure TMyImplClass.P2;
  ...
procedure TMyClass.MyP1;
  ...
var
  MyClass: TMyClass;
  MyInterface: IMyInterface;
begin
  MyClass := TMyClass.Create;
  MyClass.FMyImplClass := TMyImplClass.Create;
  MyInterface := MyClass;
  MyInterface.P1;        // calls TMyClass.MyP1;
  MyInterface.P2;        // calls TImplClass.P2;
end;
"

> > and the interface
> > method resolution clauses would be useful too.
>
> What this?
>
From Delphi 7 Help:
"
You can override the default name-based mappings by including method 
resolution clauses in a class declaration. When a class implements two or 
more interfaces that have identically named methods, use method resolution 
clauses to resolve the naming conflicts.

A method resolution clause has the form

procedure interface.interfaceMethod = implementingMethod;

or

function interface.interfaceMethod = implementingMethod;

where implementingMethod is a method declared in the class or one of its 
ancestors. The implementingMethod can be a method declared later in the class 
declaration, but cannot be a private method of an ancestor class declared in 
another module.

For example, the class declaration

type
  TMemoryManager = class(TInterfacedObject, IMalloc, IErrorInfo)
function IMalloc.Alloc = Allocate;
procedure IMalloc.Free = Deallocate;
    ...
end;

maps IMalloc's Alloc and Free methods onto TMemoryManager's Allocate and 
Deallocate methods.

A method resolution clause cannot alter a mapping introduced by an ancestor 
class.
"
> > You probably misunderstood.
> > I suggest to introduce a new 'uses' like clause where the units with
> > accessible protected class members are listed.
>
> Either you want members to be protected or not ...
>
Or you have a practical tool which is able to solve real world problems...

Martin



More information about the fpc-devel mailing list