spacer


Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com


home / experts / javascript / column55


OLE Automation in JavaScript

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Application Instances

Document templates are the link between an application and the document it supports. Document templates come in two flavors: single document templates, which allow one document of that type to be open at a time, and multiple document templates, which allow many documents of that type to be open. The following table lists the various types of Windows applications:


Single Document Interface (SDI) Applications Multiple Document Interface (MDI) Applications
Old-style Applications New-style Applications One Instance Multiple Instances
Old-style SDI applications can manage only a single document object at a time, but can support closing one document and then opening another document without starting another instance of the application. Such applications should always support running multiple instances of the application at the same time. From an object lifetime implementation point of view, an old-style SDI application is identical to an MDI application. In this discussion all comments referring to an MDI application also apply to an old-style SDI application unless mentioned otherwise. New-style SDI applications can manage only a single document object at a time, but do not support closing one document and then opening another document without starting another instance of the application. That is, if the active document is closed, the entire application shuts down. When a new document is opened, a new instance of the application is launched. If the user selects the "New" or "Open" options from the applications "File" menu, a new instance of the application is created to handle the additional file. Such applications always support running multiple instances of the application at the same time. An MDI application uses multiple document templates. It can manage many document objects in a single 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 the application can exist at a given time. An MDI application uses multiple document templates. It can manage many document objects in a single instance of the application. This type of MDI application supports running multiple instances of the application at the same time. Microsoft Word is an MDI application that supports multiple instances of the application.

It isn't difficult to associate a given application with one of the preceding application types. Simply launch the application several times, and notice if a new instance is created each time. For example, we launched Microsoft Word three times, Microsoft Excel four times, Allaire HomeSite one time, and Adobe Photoshop one time. Take a look at the resulting task bar:


Multiple Instances

As you can see, Word and Excel both support multiple instances, while HomeSite and Photoshop don't. The taskbar only reflects instances of visible applications. If an application was launched through OLE Automation, it won't appear in the taskbar until it becomes visible to the user. Therefore, you should use the Ctrl+Alt+Del combination to load the Close Program dialog (the one that lets you shut down crashing applications).


Now that we're familiar with instances, let's take another look at the ActiveXObject() and GetObject() functions:


var objVar = new ActiveXObject(class);


  • If the object is registered as a single-instance object (i.e., an out-of-process ActiveX EXE), only one instance of the object can be created. Regardless of the number of times ActiveXObject() is invoked, you will obtain a reference to the same instance of the object.
  • If the object is registered as a multiple-instance object (e.g., Microsoft Word), a new instance of the object is created. The number of times ActiveXObject() is invoked reflects the total number of instances. For example, if class is Word.Application (Microsoft Word), a new instance of the application is created.

var objVar = new ActiveXObject(class, servername);


  • This statement is the same as the preceding one, but it registers the ActiveX object on a different server.

var objVar = GetObject(, class);


  • In JScript, this statement generates an error, because JScript doesn't accept an omitted argument followed by a delimiter (,). However, the purpose of this statement (as implemented in VB) is achieved in JScript by specifying an empty (zero-length) string rather than omitting the argument.
  • In VB (and VBScript), this statement returns the current instance of the object. An error is generated only if the object cannot be found.

var objVar = GetObject("", class);


  • In JScript, this statement returns the current instance of the object. An error is generated only if the object cannot be found.
  • In VB (and VBScript), this statement returns a new instance of the object, unless the object is registered as single instance, in which case the current instance is returned. In fact, this version of the GetObject() function is equivalent to the ActiveXObject() constructor.

var objVar = GetObject(pathname);


  • If the document object is not already running, a new instance of the object's server application is launched, and the application is told to open the corresponding file. Note that the argument must represent an existing file.

var objVar = GetObject(pathname, class);


  • A new instance of the application is always launched, even if the document is already open in a running instance of the application.

We've covered every possible syntax of ActiveXObject() and GetObject(). Let's sum it all up with the following table:


TaskFunction
Create a new instance of an OLE server (that is not running)ActiveXObject()
Create a new instance of an OLE server (that is already running)ActiveXObject()
Create an instance of a class created with Visual BasicActiveXObject()
Create an instance of a class on a remote machineActiveXObject()
Launch an OLE server and load an instance of a subobject (e.g., a document)GetObject()
Retrieve an existing instance of an OLE serverGetObject()




http://www.internet.com


Produced by Yehuda Shiran and Tomer Shiran

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior


Created: January 10, 2000
Revised: January 10, 2000

URL: http://www.webreference.com/js/column55/instances.html