Creating an Instance of an Object

In order to create an Instance of an Object, a new type of variable is introduced to PowerBASIC.  These are known generally as object variables, and may only contain a reference to a COM Object, and no other value of any kind.

An object variable must be declared using its specific class.  This could be the generic DISPATCH class, or one that you explicitly define with an INTERFACE structure.  An object variable may only be used in specific situations, such as execution of an Object's Method.  It is never legal to reference an object variable in normal numeric or string expressions, nor is it possible to even display or retrieve its value without the use of the special new functions like OBJPTR.

With these points in mind, we'll now examine how to declare an object variable for both early-binding and late-binding.  In these examples, we'll also demonstrate how to create an instance of the target COM server, and place the reference in the object variable.

 

See Also

COM Programming Introduction

The PowerBASIC COM Browser

What is a Dispatch Interface?

Creating an early-bound object variable

Creating a late-bound object variable