Early-binding and Late-binding

There are two ways to create an instance of a COM Object: Early-binding, and Late-binding.  PowerBASIC supports both techniques.

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 run-time (as the program is executed).  Late-binding takes advantage of the fact that a COM 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.

Comparatively, early-binding requires that the compiler is made aware of all of the Interface's Methods and Properties that the COM client uses.  This is achieved through the use of an INTERFACE/END INTERFACE block to define each Dispatch Interface.  Unless this definition is present, PowerBASIC will be unable to validate the Interface members.

Late-binding, while slightly easier to code for, places more responsibility on the programmer to correctly specify the Interface members as they are used within the program.  Additionally, since the actual Interface and member validation occurs only at run-time, performance will be slightly reduced as compared to early-binding.  Therefore, taking the time to define an Interface and its members so that early-binding can be used is often worthwhile in order to gain a performance advantage at run-time.

However, manually coding an INTERFACE block can be a tedious job, and PowerBASIC comes to the rescue here with the new PowerBASIC COM Browser utility.  The PowerBASIC COM Browser is designed to examine a COM component and generate all of the Dispatch Interface definitions and also any equates that can assist with passing parameters.

With the aid of the PowerBASIC COM Browser, PowerBASIC makes the task of implementing early-binding very simple. 

 

See Also

COM Programming Introduction

The PowerBASIC COM Browser

Early Binding Tutorial

Late Binding Tutorial

Creating an Instance of an Object

Creating an early-bound object variable

Creating a late-bound object variable

How does the LET statement work?

New or pre-loaded?