Objects, Events, Properties and Methods

Objects

COM is based on objects. Objects expose events for the purpose of coordinating their activities with the rest of the application. Script code can be attached to the events of an object to customize behavior.

There are two main types of objects:

Objects are encapsulated and communicate through interfaces. An interface has two roles:

Interfaces are permanent - once they have been defined for an object, they are not changed. You can create multiple interfaces for a single object, enabling that object to communicate in different ways with different pieces of your application. COM defines a large number of standard interfaces.

ActiveX controls support the following items: events, properties, and methods. You need to understand the supported events, properties, and methods so that you can use a particular ActiveX object properly in your application.

Events

Events are notifications that the control sends to the container every time something affects the control, such as when a user clicks a button, types text, or hovers the mouse over an area. The control does this by firing an event, and the container transforms it into a meaningful action. The code in the container picks up the event sent by the control and executes code in response. Not all objects support all events.

To receive notification of an event, you must tell Zim that you’re interested in this event.  The following code:

FORM SET (OBJECTEVENT ’DateChanged’) MyForm.OLE_MonthView

Will cause the control named ”OLE_MonthView” on a form named ”MyForm” to generate a Zim event when it’s ’DateChanged’ event fires.  You can view the available events for a control using the ”Type Info” dialog, which is accessible from the ”Insert OLE Control” dialog.

Properties

When a control is inserted into a container, its initial properties are set. Properties act as a way of exposing variables inside a control. The control passes any changes back to the container, which is responsible for saving the properties that the control requested. In this way, the state of the control is persistent. The container design program is responsible for saving these properties when it saves the container's representation.

When the container is run and creates the control, the container must provide the control with these initial property values.

Properties are saved as part of the variables of the form. In HTML pages, the properties are saved as <PARAM> tags inside the <OBJECT> tag that specifies how to create the control.

There are several categories and sub-categories of properties. They can be implemented by the control or the container. Control properties are further broken down into custom properties (implemented by you) and stock properties (implemented by Microsoft Foundation Classes). Container properties are called ambient properties; they are further categorized as standard ambient properties, whose meanings are defined by OLE and extended properties, which are defined by a specific container. Extended properties are more properly thought of as properties of the extended control, which is inside the container that encapsulates and extends your control.

Of the four, custom control properties are the most commonly used.

To retrieve a property from a control, use the $ObjGetProperty Zim function:

LET var = $ObjGetProperty(MyForm.OLE_MonthView, 'DayOfWeek')

Methods

Methods are function calls into the control; basically, how the container tells the control to do something. There are two types of methods: customer methods and stock methods.

Customer methods are those implemented by the creator of the ActiveX Control.

Microsoft Foundation Classes provide a number of stock methods that you can easily add to your project without writing any code using wizard-type tools provided with the programming language you are using.  

To invoke a method on an object:

Let vResult = $ObjRunMethod(MyForm.OLE_MonthView, ’AboutBox’)

This will invoke the AboutBox method on the MonthView control.

Control Content

The content of a control consists of both data structures and individual properties. All content is persistent. The content provided through data structures is the data managed in the control itself, such as the text inside an edit control. Properties, on the other hand, are named characteristics and values that a control or a container can modify programmatically. Although some of these can expose bits of the actual content of the control, most are used to expose the visual and behavioral aspects of the control. Visual aspects include colors, fonts, label text, and so on. Behavioral aspects include operations such as deciding if a button should behave as the momentary variety or as the push-on/push-off sort.

Using events, then, a control transforms a user's actions into meaningful and precise triggers.