home / experts / javascript / column55 |
|
What is Binding?Before you can use the properties, methods, and events of an object model, you must first create a programmatic reference to the class containing the properties, methods, or events you wish to use. You do this by declaring a local object variable to hold a reference to the object. You then assign a reference of the object to the local variable. VB and VBScript use the Binding refers to the way in which Visual Basic code accesses objects in another application. When you use Automation from one application to work with objects in another application, the application in which you are writing Visual Basic code is the Automation controller. The application whose objects you are working with is the Automation server. When an Automation controller creates an object variable that points to an object supplied by an Automation server, Visual Basic must verify that the object exists and that any properties or methods used with the object are specified correctly. This verification process is known as binding. There are two types of binding with which Visual Basic developers need be concerned: late binding and early binding. Late BindingLate binding occurs at run time and is much slower than early binding. In late-bound Automation code, Visual Basic must look up an object and its methods and properties each time it executes a line of code that includes that object. To verify that the object and its methods and properties are specified correctly, Visual Basic must check with the operating system and with the application that supplied the object. Let's take a look at the following Visual Basic code segment:
The Early BindingEarly binding is the solution to the problem of slow Automation performance. Early binding occurs at compile time rather than run time, so if your code is saved in a compiled state, binding is complete before the code is even run. When using early binding, Visual Basic doesn't need to continually verify the object information while using the object during the execution of the application. Not all Automation servers support early binding. The Automation server must provide a type library, containing information about the server's objects, methods, and properties. To take advantage of early binding, you must set a reference to the Automation server's type library. Visual Basic loads the type library into memory, which enables it to recognize these objects and bind them when the code is compiled. The following code segment shows how to create an early bound interface to an object:
|
Produced by Yehuda Shiran and Tomer Shiran
Created: January 10, 2000
Revised: January 10, 2000
URL: http://www.webreference.com/js/column55/binding.html