javascript| Tutorial
Using OLE Automation in JavaScript
2. What is Binding
Before you can apply the properties, methods, and events of an object model, you must first create a planned reference to the class that contains the attributes, methods, or events that you want to apply. You can do this by declaring a local object variable to keep a reference to the object. Then, you specify an object's application for the local variable.
VB and VBScript use the CreateObject () function to enable and return a reference to a Automation object when JScript uses this ActiveXObject () constructor.
In fact, binding refers to the way that Visual Basic code accesses other application objects. When you use automation from an application to process objects in another application, the application you write Visaul Basic code is a automation controller. The application you are working on is the Automation server. When a automation controller creates a variable that points to an object supplied by the Automation server, Visual Basic must verify that the object exists and that any properties and methods of the object are specified correctly. This verification process is called "binding". There are two types of bindings that Visual Basic program developers use to note: Late binding (late binding) and early binding (early bound).
Late binding
Late binding occurs at run time and is slower than early binding. In a late-bound automation code, Visual basic must query the object and its methods and properties each time it executes the line code that includes that object. To verify that this object and its methods and properties are correctly specified, Visual Basic must be checked with the application of the operating system and support objects. Take a look at the visual Basic code below:
Dim Wdapp as Object
Set Wdapp = CreateObject ("Word.Application")
This wdapp variable is defined as a generic type of object. When this variable is declared, Visual Basic does not know what type of object it belongs to, so you have to set aside a certain amount of memory for the object. Since a particular object reference is assigned to a generic variable, the application has no way of knowing what the object's interface is made of. The application is bound to the user interface only at run time. Therefore, whenever you refer to a new object, Visual Baisc must check the system registration to obtain information about the object.
Early binding
Early binding is a good solution for slow automation performance. Early binding occurs at compile time rather than at run time, so if your code is saved in the compile phase, the binding is over before the code runs. When using early binding, Visual Basic does not need to continuously validate object information, but instead uses objects during application execution.
In addition, not all Automation servers support early binding. This automation server must support a type library that contains information about the server objects, methods, and properties. In order to take advantage of early binding, you must set a reference for the type library of the Automation server. Visual basic loads the type library into memory, which enables it to recognize these objects and bind them when code is compiled. The following code snippet shows how to create an early-bound interface for an object:
Dim Wdapp as Word.Application
Set Wdapp = CreateObject ("Word.Application")