Quick start manual
10-6
Delphi Language Guide
Implementing interfaces
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.
Changing inherited implementations
Descendant classes can change the way a specific interface method is implemented
by overriding the implementing method. This requires that the implementing
method be virtual or dynamic.
A class can also reimplement an entire interface that it inherits from an ancestor class.
This involves relisting the interface in the descendant class’s declaration. For
example,
type
IWindow = interface
['{00000115-0000-0000-C000-000000000146}']
procedure Draw;
ƒ
end;
TWindow = class(TInterfacedObject, IWindow) // TWindow implements IWindow
procedure Draw;
ƒ
end;
TFrameWindow = class(TWindow, IWindow) // TFrameWindow reimplements IWindow
procedure Draw;
ƒ
end;
Reimplementing an interface hides the inherited implementation of the same
interface. Hence method resolution clauses in an ancestor class have no effect on the
reimplemented interface.