Object Data Types

Object variables may only contain a reference to a COM Object, and no other value of any kind.  An object variable must be declared by its specific class, which could be the generic "DISPATCH" class, or one that is explicitly defined with an INTERFACE structure.  For example:

' Generic Dispatch Object variable

DIM oWord AS DISPATCH            

' Interface-specific Object variable

DIM oExcel AS "Excel.Application"

An object variable may only be used in specific situations, such as execution of an Object Method.  It is never legal to reference Object variables in normal numeric or string expressions, nor is it possible to even output their value without the use of the special new functions like OBJPTR.

A Dispatch Object is one that communicates through the IDispatch interface, which is the most flexible method, as it supports both named and optional parameters.  While an object may support hundreds of functions (known as Methods or Properties) in Dispatch Objects, they are all accessed through a single entry point, called Invoke.

So how does the object tell one from another?  By encoding every function (Method or Property), and every named parameter as a special numeric, Long-integer value known as a Dispatch ID, or DispID for short.  When a Dispatch Client calls a Method in a Dispatch Object, it passes one or more DispID's to tell the object precisely which Method and which parameters it expects to utilize.  Importantly, PowerBASIC handles most all of these messy details for you, so all you really need to know are the names of the functions and parameters.

Dispatch objects require that all parameters, return values, and assignment values be passed only as Variant Variables.

PowerBASIC can access Dispatch Objects through "Early Binding" or "Late Binding".  Late binding, the simpler method, offers the most flexibility.  You don't need to declare Methods, Properties, and parameters in advance, as everything is resolved at the time the program is executed.  A Dispatch Object knows a lot about itself, including information about all of its member functions.  However, for that very reason, the validity of these references is not checked at compile time.  Virtually everything is done at run time.

 

See Also

COM Programming Introduction

What is a COM component?

What is a Dispatch Interface?

Methods and Properties

Parameters