Quick start manual

10-10
Delphi Language Guide
Interface references
Interface references are typically managed through reference-counting, which
depends on the _AddRef and _Release methods inherited from IInterface. Using the
default implementation of reference counting, when an object is referenced only
through interfaces, there is no need to destroy it manually; the object is automatically
destroyed when the last reference to it goes out of scope. Some classes implement
interfaces to bypass this default lifetime management, and some hybrid objects use
reference counting only when the object does not have an owner.
Global interface-type variables can be initialized only to nil.
To determine whether an interface-type expression references an object, pass it to the
standard function Assigned.
Interface assignment-compatibility
Variables of a given class type are assignment-compatible with any interface type
implemented by the class. Variables of an interface type are assignment-compatible
with any ancestor interface type. The value nil can be assigned to any interface-type
variable.
An interface-type expression can be assigned to a variant. If the interface is of type
IDispatch or a descendant, the variant receives the type code varDispatch. Otherwise,
the variant receives the type code varUnknown.
A variant whose type code is varEmpty, varUnknown, or varDispatch can be assigned
to an IInterface variable. A variant whose type code is varEmpty or varDispatch can be
assigned to an IDispatch variable.
Interface typecasts
An interface-type expression can be cast to Variant. If the interface is of type IDispatch
or a descendant, the resulting variant has the type code varDispatch. Otherwise, the
resulting variant has the type code varUnknown.
A variant whose type code is varEmpty, varUnknown, or varDispatch can be cast to
IInterface. A variant whose type code is varEmpty or varDispatch can be cast to
IDispatch.
Interface querying
You can use the as operator to perform checked interface typecasts. This is known as
interface querying, and it yields an interface-type expression from an object reference
or from another interface reference, based on the actual (runtime) type of the object.
An interface query has the form
object as interface
where object is an expression of an interface or variant type or denotes an instance of
a class that implements an interface, and interface is any interface declared with a
GUID.