Home  >  Article  >  Web Front-end  >  Javascript example tutorial(20) OLE Automation(2)

Javascript example tutorial(20) OLE Automation(2)

黄舟
黄舟Original
2016-12-19 17:23:061243browse

Using OLE Automation in javaScript

2. What is binding

Before you use the properties, methods and events of an object model, you must first create a program reference to contain the properties, methods you want to use Or the class of the event. You can do this by declaring a local object variable to hold a reference to the object. Then, you specify the application of an object for the local variable.

VB and VBScript use the CreateObject() function to allow and return a reference to an Automation object when Jscript uses the ActiveXObject() constructor.

In fact, binding refers to the method by which Visual Basic code accesses objects in other applications. When you use Automation from one application to manipulate objects in another application, the application in which you write Visaul Basic code is an Automation controller. The application you are handling objects in is the Automation server. When an Automation controller creates a variable that points to an object provided by the Automation server, Visual Basic must verify that the object exists and that any properties and methods used on the object are correctly specified. This verification process is called "binding". There are two types of binding that Visual Basic program developers should be aware of: late binding and early binding.

Late binding

Late binding happens at runtime and is slower than early binding. In late-bound Automation code, Visual Basic must query the object and its methods and properties each time it executes a line of code that includes that object. In order to verify that the object and its methods and properties are correctly specified, Visual Basic must check with the operating system and the application that supports the object. Let's look at a piece of Visual Basic code:

Dim wdApp As Object

Set wdApp = CreateObject("Word.application")


This wdApp variable is defined as a general type of object. When this variable is declared, Visual Basic does not know what type of object it is, so you must set aside a certain amount of memory for this object. Since specific object references are assigned to ordinary variables, the application has no way of knowing what the object's interface consists of. Only at run time is the application bound to the user interface. Therefore, whenever you reference a new object, Visual Baisc must check the system registry to obtain information about the object.

Early binding

Early binding is a good solution to slow Automation performance. Early binding occurs at compile time rather than run time, so if your code is saved during the compile phase, the binding will be completed before the code is run. When using early binding, Visual Basic does not need to continuously verify object information, but uses the object as the application executes.

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 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 allows it to identify these objects and bind them when the code is compiled. 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 Javascript example tutorial (20) OLE Automation( 2). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn