Javascript example tutorial (20) OLEAutomation (2)

Source: Internet
Author: User
Javascript example tutorial (20) OLEAutomation (2) use OLE Automation in javaScript

2. What is binding

Before you apply the attributes, methods, and events of an object model, you must first create a planned reference to a class that contains the attributes, methods, or events you want to apply. You can achieve this by declaring a local object variable to keep a reference to this object. Then, you need to specify an object application for the local variable.

VB and VBScript use the CreateObject () function. Now, when Jscript uses this ActiveXObject () constructor, it is allowed for an Automation Object and returns a reference.

In fact, binding refers to how Visual Basic code accesses other application objects. When you use Automation to process objects in another application from an application, the application that you write Visaul Basic code is an Automation controller. The application that you are processing the object is an Automation server. When an Automation controller creates a variable pointing to an object provided by the Automation server, Visual Basic must verify that the object exists and that any attributes and methods of the object are correctly specified. This verification process is called "binding ". There are two types of binding for Visual Basic program developers. Note: late binding (late binding) and early binding (early binding ).

Late binding

Late binding occurs during running time and is slower than early binding. In the late binding Automation code, Visual Basic must query the object and its methods and attributes every time it executes the line code containing that object. To verify that the object and its methods and attributes are correctly specified, Visual Basic must use the operating system and applications that support the object to check. The following is a piece of Visual Basic code:

Dim wdApp As Object

Set wdApp = CreateObject ("Word. application ")


This wdApp variable is defined as a general type object. When this variable is declared, Visual Basic does not know what type of object it belongs to, so you must set aside a certain amount of memory for this object. Since a specific object reference is specified to a common variable, the application cannot know what the interface of the object is. The application is bound to the user interface only at the running time. Therefore, no matter when you reference a new object, Visual Baisc must check the system registration to obtain the object information.

Early binding

Early binding is a good solution to slow Automation performance. Early binding occurs during compilation instead of running. Therefore, if your code is saved in the compilation phase, the binding has ended before the code is run. When early binding is used, Visual Basic does not need to continuously verify the object information, but uses the object during application execution.

In addition, not all Automation servers support early binding. The Automation server must support a type library that contains information about server objects, methods, and properties. To use early binding, you must set a reference for the Type Library of the Automation server. Visual Basic loads the Type Library to the memory, so that it can recognize these objects and bind them during code compilation. The following code snippet shows how to create an early binding interface for an object:

Dim wdApp As Word. Application

Set wdApp = CreateObject ("Word. Application ")

The above is the content of the Javascript instance tutorial (20) OLE Automation (2). For more information, see PHP Chinese Network (www.php1.cn )!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.