Quick start manual
10-4
Delphi Language Guide
Implementing interfaces
Interface properties
Properties declared in an interface are accessible only through expressions of the
interface type; they cannot be accessed through class-type variables. Moreover,
interface properties are visible only within programs where the interface is compiled.
In an interface, property read and write specifiers must be methods, since fields are
not available.
Forward declarations
An interface declaration that ends with the reserved word interface and a semicolon,
without specifying an ancestor, GUID, or member list, is a forward declaration. A
forward declaration must be resolved by a defining declaration of the same interface
within the same type declaration section. In other words, between a forward
declaration and its defining declaration, nothing can occur except other type
declarations.
Forward declarations allow mutually dependent interfaces. For example,
type
IControl = interface;
IWindow = interface
['{00000115-0000-0000-C000-000000000044}']
function GetControl(Index: Integer): IControl;
ƒ
end;
IControl = interface
['{00000115-0000-0000-C000-000000000049}']
function GetWindow: IWindow;
ƒ
end;
Mutually derived interfaces are not allowed. For example, it is not legal to derive
IWindow from IControl and also derive IControl from IWindow.
Implementing interfaces
Once an interface has been declared, it must be implemented in a class before it can
be used. The interfaces implemented by a class are specified in the class’s declaration,
after the name of the class’s ancestor. Such declarations have the form
type className = class (ancestorClass, interface
1
, ..., interface
n
)
memberList
end;
For example,
type
TMemoryManager = class(TInterfacedObject, IMalloc, IErrorInfo)
ƒ
end;