Previous Document Next Document

Understanding automation : What are the main elements of automation? : What is an object model?


What is an object model?

An object model represents the hierarchy of items (or “objects”) that make up an application and defines the interrelationships of the objects within that hierarchy. In an object model, each object is a child of another object, which is a child of yet another object, and so on. Furthermore, each object in an object model is defined by a property, a method, or an event, or a combination of these items.

Besides providing a high level of structure, an object model also lets you use object types (or “classes”) in various ways. For example, a Shape object of type “group” is used to contain other Shape objects, each of which is from type “group” or some other type, such as “rectangle,” “curve,” or “text.”

This high level of organization makes the object model easy to use, yet powerful.

How is an object model used in automation?

Automating CorelDRAW is accomplished by using the object model of the application to access the various objects in a document and make changes to those objects.

In CorelDRAW, the Application object represents the top of the object hierarchy: the program itself. All objects are children or grandchildren (or great-grandchildren, and so on) of the application.

Starting with the Application object, you can “drill down” through the layers of hierarchy in the object model until you find the desired, and usually the more specific, object. To reference the desired object, you must use a standard notation to separate each level of the object hierarchy. As in many object-oriented languages, the automation environment requires the use of a period or “dot operator” ( . ) to indicate that the object on the right is a member (or child) of the object on the left.

Application.Documents(1).Pages(1).Layers(1).Shapes(1).Name = "ABC"

An object requires its full hierarchical (or “fully qualified”) reference unless a shortcut is available to it (or unless it has an implicit or implied meaning). An object shortcut is merely a syntactic replacement for the long-hand version of an object. For example, the shortcut object ActiveLayer replaces the long-hand version Application.ActiveDocument.ActivePage.ActiveLayer, while the object shortcut ActiveSelection replaces the long-hand version Application.ActiveDocument.Selection.

 
For more information on object shortcuts, see Using object shortcuts.

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.