2.2.3 Components and Instances

In the object-oriented model of Visual LANSA there is an important distinction between a component and an instance of a component.

When you include a component in a form, you do not include the actual component, only an instance of it. The component serves as a model for the instance: all instances of a component have the same properties, events and methods as the component. However, you can change property values and create event routines for a specific instance. When you do so the component itself remains unchanged.

Let's use the push button component as an example. Every time you drag a button to a form, it will have the same:

You then modify some of the properties, usually at least the caption (for example OK), and you write logic in the Click event of the button.

So every instance of a button in your application shares the characteristics of a button component but has its own individual character as well.

The same happens when you drag fields to a form. However, most often you use the instance of a field as such without changing it in any way.

Similarly, instances of a form can be included in another form. For example you might create a standard form used by many applications. To use this form in an application you include it in the application's main form (owner form). The included form is an instance of the standard form. You can modify the properties of the instance, for example its height and width or its caption, but the standard form does not change.

You Can Have Multiple Instances of a Component on the Same Form

In the case of controls, you often have several instances of a component on the same form, for example push-buttons, check boxes or tab sheets. The instances have different names. For example two push-buttons on the same form are named #PHBN_1 and #PHBN_2 by default.

You can also include multiple instances of a field on the same form, but there is seldom reason to do so.

You include several instances of a form in an owner form when you want to be able to display several identical windows simultaneously. For example you might want your application to have more than one window showing employee details open at the same time. In this case you include several instances of the form on the owner form.

Changing the Component

You can change the component definition of a field or a form. You cannot change the definitions of controls (for example buttons, lists, tab sheets). They are predefined.

When you change the definition of a field or a form, their instances also change, except for cases where the instance specifically overrides the change.

For example when you change the description of the field in the field definition, the descriptions of all the instances of the field on all forms are changed. So the instance is not just a copy, it is actively linked to the component.

The description would remain unchanged only if in your application you had specified to use a caption which was specific to the instance.

Similarly, when you change the definition of a form, for example its caption, the caption of all its instances is changed. Again, this does not happen if an instance has an overriding caption.