JavaScript Instance tutorial OLE Automation (5)

Source: Internet
Author: User
Tags object homesite interface ole
javascript| Tutorial

Using OLE Automation in JavaScript

5. How to handle an instance of an application

A document template is a connection between an application and the document it supports. There are two types of document templates: a single document, which can open only one type of document at a time, and multiple document templates, which allow multiple documents to be opened at the same time. The following table lists the various types of Windows applications:

Single-Document interface (SDI) applications

Single-Document interface (MDI) applications

Old type of application

New types of applications

An instance

Multiple instances

The old SDI application can only manage one document at a time, but it supports closing a document and opening another document without having to start another instance of the application. Such an application always supports multiple instances of the application running every time. From an object's lifecycle implementation perspective, the old type of SDI application is the same as a more MDI application.

A new type of SDI application can manage one document object at a time, but it does not support closing a document and opening another document without having to start another instance of the application. That is, if the active document is closed, the entire application shuts down. When a new document is opened, an instance of the new application is loaded. If a user chooses "new" or "Open" from the application's "File" menu, a new instance of the application is created to process the attached file. Such an application always supports running the application once.

MDI applications use multiple document templates. It can manage multiple documents in one instance of the application. This type of MDI application does not support running multiple instances of the application at the same time. Only one instance of an application can exist at a time.

MDI applications use multiple document templates. It can manage multiple document objects in a single instance of the application. This type of MDI application supports multiple instances of the application running every time. Microsoft Word is an MDI application that supports multiple instances of the application.



It is not difficult to associate a given application with the above application type. You can simply load the application repeatedly and notice whether a new instance is created each time.

Using OLE Automation in JavaScript

5. How to handle an instance of an application

For example, we loaded Microsoft Word three times, Microsoft Excel loaded four times, Allaire homesite loaded once, Adobe Photoshop loaded once, and then look at the results of the task bar, as shown in Figure 1.

(Figure 1)

As shown in Figure 1, you can see that both Word and Excel support multiple instances, which homesite and Photoshop do not support. This task bar knowledge responds to instances of the visual application. If the application is loaded only through OLE Automation, it will not appear on the taskbar unless it is visible. Therefore, you should use the Ctrl+alt+del key combination to load the Close Program dialog box (which allows you to completely shut down the application).

Now that we may be familiar with the example, let's look at the ActiveXObject () and GetObject () functions:

var objvar = new ActiveXObject (class);

If an object is registered as a single instance object, then only one instance of the object is created. No matter how many times ActiveXObject () is invoked, you will get a reference to the same instance of the object.

If an object is registered with multiple instance objects (such as Microsoft Word), a new instance of the object is created. The number of times the ActiveXObject () is invoked reflects the total number of instances. For example, if the class is Word.Application, then a new instance of the application will be created.

var objvar = new ActiveXObject (class, ServerName);

This statement is the same as the previous statement, but it registers an ActiveX object on a different server:

var Objvar = GetObject (, Class);

In JScript, this statement will produce an error because JScript does not accept an omitted argument followed by a comma (,). However, the purpose of this statement is to implement specifying an empty string in JScript instead of simply omitting the argument. In VB and VBScript, this statement returns an instance of the object. An error occurs only when an object cannot be found:

var Objvar = GetObject ("", Class);

In JScript, this statement returns the current instance of the object. An error occurs only when an object cannot be found.


Using OLE Automation in JavaScript

5. How to handle an instance of an application

In VB and VBScript, this statement returns a new instance of an object, unless the object is registered as a single instance, and if so, the current instance is returned. In fact, the version of the GetObject () function is the ActiveXObject () constructor.

var Objvar = GetObject (pathname);

If the document object is not running, a new instance of the object's server application is loaded, and the application is notified to open the appropriate file. It is worth noting that the parameters must represent the existing files:

var Objvar = GetObject (pathname, Class);

The new instance of the application is always loaded, even if the document is already open in the state where the application instance is running.

We have now discussed the various possible syntaxes of ActiveXObject () and GetObject (). Finally, let's take a look at the summary table below:

Task

Function

Create a new instance of the OLE server that does not run

ActiveXObject ()

Creates a new instance of the OLE server that is already running

ActiveXObject ()

Use Visual Basic ActiveXObject () to create an instance of a class

ActiveXObject ()

Create an instance of a class using the remote machine's ActiveXObject ()

ActiveXObject ()

Mount an OLE server and mount an instance of subject

GetObject ()

Retrieving an existing instance of an OLE server

GetObject ()




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.