JavaScript Instance tutorial OLE Automation (4)

Source: Internet
Author: User
Tags object ole reference string
javascript| Tutorial

Using OLE Automation in JavaScript

4. How to retrieve an instance of the existence of a automation object

JScript supports the GetObject () function in the same Visual Basic. Its general syntax is as follows:

var Objvar = GetObject ([pathname][, class]);

OBJVAR specifies a variable to hold the reference to the instantiated object. Pathname is the full path and the file name that contains the ActiveX object. class specifies the objects in the form of the string. The class parameter uses the syntax library.object, which is the same as the first parameter of the ActiveXObject function.

In a nutshell, the GetObject () function accesses an ActiveX server in a specified file. Although the two parameters are optional, at least one of the parameters should be supplied. The GetObject () function is used when there is a current instance of an ActiveX object. It does not create a new instance, such as the ActiveXObject () function.

If you specify an empty character window (""), GetObject () returns a new instance of an object, unless the object is registered as a single instance, in which case the current instance is returned. However, if pathname is not specified, the current instance of the object is returned. If pathname is not specified, an error is generated and no current instance of the object is found. Note here that the GetObject () function cannot be used to obtain a reference to a class created by Visual Basic.

Some applications allow you to access special parts of the object library. To use an exclamation point (!) after the filename, the next string is the part that identifies the library you want to activate. To get information on how to create this string, you can see the technical documentation for the Automation server. For example, a file in a paint reference program might have several layers. You can use the following code in a picture (such as SCHEMA. CAD) activates a layer:

var Objvar = GetObject ("C:\\cad\\schema.") Cad! Layer2 ");

Some files (other libraries) may support more classes. For example, a paint file might support three different classes: application objects, drawing objects, and tool bar objects. Since you can only refer to a single object, you must specify which class you are referring to:

var Objvar = GetObject ("C:\\drawings\\sample.") DRW "," figment.drawing ");

In the previous example, Figment is the name of a paint application, and drawing is one of the object types it supports.



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.