Object Data Type

Purpose

The Object data type is a 32-bit (4-byte) address that refer to COM objects within an application or within some other application.

Syntax

Dim name As Object

Description

When you create an application in GFA-BASIC 32, you work with objects. You can use objects provided by GFA-BASIC 32 - such as controls, forms, and data access objects. You can also control other applications' objects from within your GFA-BASIC 32 application.

Declaring an object variable with the As Object clause creates a variable that can contain a reference to any type of (OLE) object. However, access to the object through that variable is late bound; that is, the binding occurs when your program is run. To create an object variable that results in early binding, that is, binding when the program is compiled, declare the object variable with a specific class ID. For example, you can declare and create the following Microsoft Excel references:

Dim xlApp As Object

Dim xlBook As Object

Dim xlSheet As Object

Set xlApp = CreateObject("Excel.Application")

Set xlBook = xlApp.Workbooks.Add

Set xlSheet = xlBook.Worksheets(1)

After you declare an object variable, you must assign an object reference to the variable before you can use the object's properties, methods, and events. You can assign a reference to a new object in a Set statement by using the CreateObject or GetObject function.

The Object data type stores a pointer to an IDispatch interface, the late binding mechanism of COM. When a COM object provides an IDispatch interface, the properties and methods can be executed through a standard function called Invoke. Rather than executing a property or method directly, as with early binding, the Invoke function takes numerous parameters describing the property or method to call, the possible parameters converted to Variants, an exception info block for returning error information, and some more. Invoke itself must lookup the name of the property or method in the COM library and then call it by its address. Calling Invoke for a property or method is a time consuming process, therefore.

Example

OpenW 1

Dim oForm As Object

Set oForm = Win_1.Object

Win_1.AutoRedraw = ' Fast

oForm.AutoRedraw = ' Slow

Do

Sleep

Until Me Is Nothing

 

Sub Win_1_OnCtrlHelp(Ctrl As Object, x%, y%)

' IDispatch reference to the control.

Print Ctrl.WhatsThisHelpID // Slow

EndSub

See Also

Set, CreateObject, GetObject

{Created by Sjouke Hamstra; Last updated: 20/10/2014 by James Gaite}