If you’ve ever developed object-oriented code in C++, Delphi, or Java, you’re already familiar with programming-related concepts such as "objects," "classes," "properties," and "methods." However, let’s reexamine these terms as they apply to automating Corel DESIGNER, CorelDRAW, and Corel PHOTO-PAINT.
This topic contains the following subtopics:
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 Corel DESIGNER, CorelDRAW, or Corel PHOTO-PAINT 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 Corel DESIGNER, CorelDRAW, and Corel PHOTO-PAINT, 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.
ActiveLayer
Application.ActiveDocument.ActivePage.ActiveLayer
ActiveSelection
Application.ActiveDocument.Selection.
For more information on object shortcuts, see Using object shortcuts.
A class is the definition or description of an object. A class outlines the properties, methods, and events that apply to a type of object in an application; it acts as a template for all objects of that type class. To use a metaphor, the class "car" is a small vehicle with an engine and four wheels.
An object is an instance of a class. To extend the car metaphor, the actual, physical car purchased for the purposes of driving is an object (that is, an instance of the class "car").
In the context of Corel DESIGNER, CorelDRAW, and Corel PHOTO-PAINT, each open document is an instance of the Document class, each page in the document is an instance of the Page class, and each layer (and each shape on each layer) are more instances of more classes. For example, Document represents the Document class in the software program. However, ActiveDocument represents an object within that class because it makes specific reference to one object.
Document
ActiveDocument
As previously discussed, objects are often made up of other smaller objects. For example, a car contains four objects of the class "wheel," two objects of the class "headlight," and so on. Each of these child objects has the same properties and methods of its class-type. This parent/child relationship of objects is an important one to recognize, particularly when referencing an individual object.
Some classes "inherit" features from their parents. For example, in the context of Corel DESIGNER, CorelDRAW, and Corel PHOTO-PAINT, the Shape type has many subtypes (or "inherited types"), including Rectangle, Ellipse, Curve, and Text. All these subtypes can make use of the basic members of the Shape type, including methods for moving and transforming the shape and for setting its color. However, the subtypes also have their own specialist members; for example, a Rectangle can have corner radii, whereas Text has an associated Font property.
A collection is similar to an array of objects; it is an object that contains a group of objects that are similar in type. These objects share the same properties, methods, and events, and they are uniquely identified within the collection by their index number or their name. Collection objects act in the same manner and are always plural.
For example, Documents represent the Documents collection class in the software program. However, Documents.Item(1) references the first Document object in that collection.
Documents
Documents.Item(1)
A property is like an adjective in that it represents an attribute or characteristic quality of an object. Properties can be returned or set, or they can be read-only.
Most classes have properties. As an illustration, the properties of the class "car" are that it is small, it has an engine, and it has four wheels. Every instance of the class "car" (that is, every object in that class) also has properties such as color, speed, and number of seats. Read-only properties are fixed by the design of the class; for example, the number of wheels or seats does not (usually) vary from car to car. However, other properties can be changed after the object has been created; for example, the speed of the car can go up and down, and, with a bit of help, its color can be changed.
In the context of Corel DESIGNER, CorelDRAW, and Corel PHOTO-PAINT, Document objects have a name, a resolution, and horizontal and vertical ruler units; individual shapes have outline properties and fill properties, as well as a position and a rotation factor; and text objects have text properties, which may include the text itself. For example, ActiveDocument.Name represents the Name property of a Document object; it specifies the name of the active document.
ActiveDocument.Name
A method is like a verb in that it represents an action that can be performed by or on an object. In the example of a class "car," the car can be made to go faster and slower, so two methods for the class are "accelerate" and "decelerate."
In the context of Corel DESIGNER, CorelDRAW, and Corel PHOTO-PAINT, documents have methods for creating new pages, layers have methods for creating new shapes, and shapes have methods for applying transformations and effects. For example, ActiveDocument.Close represents the Close method of a Document object; it closes the active document.
ActiveDocument.Close
An event is like a noun in that it represents an action that takes place within an object. An event is triggered by an action, such as a mouse click, a key press, or a system timer. An event can be coded to trigger appropriate response in its object.
For example, the ActiveDocument.AfterSave event triggers an action in the Document object after it has been saved.
ActiveDocument.AfterSave
An enumeration (also called an "enumerated type") represents a fixed value in the procedures and functions of the coding for a macro. Whereas a variable temporarily stores a changing data value, the value of an enumeration does not change.
A constant is an instance of an enumeration, and an enumeration groups similar constants together.
For example, cdrPageOrientation is an enumeration, yet it contains several constants, including cdrPortrait and cdrLandscape.
cdrPageOrientation
cdrPortrait
cdrLandscape