Name
Interface Keyword
Syntax
unitName; interfaceDeclarations... implementationDeclarations... end. typeName= interface ... end; typeName= interface(BaseInterface, ...) ... end;
Description
The interface keyword serves two entirely
unrelated functions.
The most common use for interface is to start the
interface section of a unit. Every unit must have an interface
section, although it can be empty. Declarations in an interface
section are exported and can be used by any other unit that uses the
unit.
The second use is to declare an interface type. An interface defines an abstract protocol that can be implemented by a class. An interface can have method and property declarations, but no field declarations. All interface declarations are public.
Interface Section
The
usesdeclaration, if it is present, must be the first declaration in the interface section.Every function, procedure, and non-abstract method declared in the interface section must be defined in the implementation section. The parameter names and types in the definitions must match the declarations in the interface section.
Interface Types
Although interfaces look and act like COM interfaces, you are not restricted to using COM. Interfaces are a powerful and underused technique for writing object-oriented code. Interfaces feature automatic memory management and increased polymorphism. Chapter 2, discusses this topic at length.
Delphi automatically type casts an interface reference to a GUID when necessary. Thus, you ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access