Early Binding

Early binding differs from late binding in two very important ways:

1.        Early binding allows the compiler to perform type checking.

2.        Early binding knows the Dispatch ID so it's more direct and faster.

For the most part, the syntax for early binding is exactly the same as that for late-binding.  All that is needed is to let PowerBASIC know that early binding should be used instead of late binding.  This is done by simply changing the keyword DISPATCH to the desired Interface.  In our source code, we change the following:

DIM oWord AS DISPATCH

LET oWord = NEW DISPATCH IN "Word.Application.8"

to:

DIM oWord AS WordApplication

LET oWord = NEW WordApplication IN "Word.Application.8"

The only other change is to specify all the needed Interfaces and their respective members.  This is called Interface Structure, and this is where the PowerBASIC COM Browser becomes extremely useful - trying to create the Interface Structure without the PowerBASIC COM Browser is a complex and tedious task.

Usually it is quickest to just include every possibly Interface and Enumeration in our code, regardless of whether we need to use them all.  Including the entire Interface definition and Enumeration only increases the size of the source code, and has no impact on the size of the compiled code.  We can do this using the following technique:

1.        Choose File | Select All Interfaces from the pull-down menu.

2.        Choose File | Save Interface to File from the pull-down menu.

3.        Enter a name, such as WORD.INC, and choose Save.  Word 97's Automation Interface structure is quite large, so it may take a few seconds to enumerate and save.

4.        Type the following at the top of your source code:

#INCLUDE "WORD.INC"

5.        Compile and Run the code.

That is all there is to it…!

Multiple Interfaces and Enumerations can be copied to the clipboard by holding down the CTRL key as each item is selected.  A range can be selected by selecting the first item then while holding down the SHIFT key, select the last item in the range - all items in the range will be highlighted.

Finally, choose the File | Save Interface to Clipboard menu item from the pull-down menu or right-clicking the Interfaces list box and choose Copy from the context menu.

For additional information on using the PowerBASIC COM Browser utility, please see The PowerBASIC COM Browser User Interface topic.

 

See Also

COM Programming Introduction

The PowerBASIC COM Browser

Early-binding and Late-binding

Late Binding Tutorial

How does the LET statement work?