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.
An interface query returns nil if object is nil. Otherwise, it passes the GUID of interface to the
QueryInterface
method in object, raising an exception unless
QueryInterface
returns zero. If
QueryInterface
returns zero
(indicating that object's class implements interface), the interface query returns an interface reference to object.
200