2.19 Data Classes

Data classes are components that define a value but are not visible. In most cases a data class corresponds to a repository field.

When you drag a field from the repository to a form, you create a visualization of the field. To try this out, drag the field  #SALARY  to a form. This definition is created for the field:

DEFINE_COM class(#SALARY.Visual) name(#SALARY)

Note that the class here is #SALARY.Visual. The Visual class creates a component which displays a value and can accept user input. In the Details tab of the editor you can see all the properties of the Visual class. Many of them control the way the field is displayed.

Now, delete the Visual qualifier from the name of the class:


This changed statement now defines the data class component of #SALARY.  The field is no longer displayed on the form (because it is not visualized).The data class component simply describes a value, in other words the basic characteristics of the component: its data type, length, decimals etc.

Display the Details tab to see the properties of the #SALARY data class. Note that it has very few properties compared to the properties of the #SALARY.Visual class.

Using a Data Class

You can use a data class component:

To create a variable

When you want to create a simple variable which has the characteristics (type, properties etc.)  of a field or a primitive data class.

See Data Classes as Variables.

In a spin edit box

When you want a numeric field to be displayed with spin edit buttons, add a spin edit box to your form and then specify the field as the value of the DataClass property of the spin edit.

For example, if you add the field #SALARY to a form, it is displayed as a plain input/output field. If you want this field to be displayed with spin buttons, you must first add a spin edit box to your component and then assign the field #SALARY as the DataClass property of the spin edit. The spin edit box will then behave exactly like the #SALARY field apart from the spin buttons.

Spin buttons are used to increment numbers and therefore only a numeric field can be used as the value of the DataClass property in a spin edit box.

In a combo box

When you want to apply the characteristics (such as type and length) and rules of a field to the value entered in the edit portion of the combo box,  specify the field as the value of the combo box's DataClass property.

For example, if you want the value entered in the combo box to be a numeric value accepted by the #SALARY field, make #SALARY the value of the combo box's DataClass property.

Another, less common use for the DataClass property of a combo box is to show the value of a specified field in the edit portion of the combo box.

Normally the edit portion of the combo box shows the value of the current item of the first column (DisplayPosition 1). If you want the value of another field than the one that was used as the source of its first column to be shown in the edit area, specify this field as its DataClass. This field can be one of the fields used as the source of other columns in the combo box or any other field in the repository. Normally you would not specify any of the fields used as columns in the combo box as the DataClass value because if you want a column displayed in the edit area, it is simpler to change its DisplayPosition to 1. A more typical usage would be to create a field that combines the current values of several columns and use this field as the DataClass so that all the values are visible in the edit area. 

For example if the combo box has a column for the first name and surname of employees, a field that concatenates the values of these two fields could be used as the DataClass.

In a property sheet

When you want to create property sheet entries. A data class needs to be assigned to every entry in the property sheet to handle how the value for the entry is displayed and modified. See Property Sheets.

Data Classes as Variables

You can define data class components based on any field enrolled in the repository. Here are some examples of how you would define your own data class components:







And here is how you would use commands to manipulate the components:


SET com(#SALARY) value(34000.56)

SET com(#OLD_SALARY) value(12567.45)

SET com(#NEW_SALARY) value(#OLD_SALARY.Value)

IF cond('#SALARY.Value <= #OLD_SALARY.Value')

In the above #SALARY, #OLD_SALARY and #NEW_SALARY are all components of the class #SALARY. The class defines what they are, how long they are, what number of decimals they have, etc.

The important thing to note is that #SALARY in the LANSA repository defines a class of an object. It does not define a component instance. The instances are defined in the DEFINE_COM statements and there may be many instances with many different names . By default a component has the same name as the class to make coding easier.

This concept is relatively easy to understand when dealing with your own things such as #EMPNO,  #SALARY, #GIVENAME because they are such simple things.

However, your repository contains many other classes shipped with LANSA. These components are sometimes referred to as 'primitives' and their names start with #PRIM_.  For example #PRIM_ALPH is a primitive alphanumeric data class and #PRIM_NMBR is a primitive numeric data class. The primitive components can be used like your own classes (or fields) to define components within your code.

For example to define a string variable in your code, you could define a #MYSTRING component based on the primitive alphanumeric variable:



And then use this component in your code:


SET com(#MYSTRING) value(#EMPNO)

Similarly, to define a numeric variable in your code, you could define a #MYNUMBER component based on the primitive numeric data class:



The primitive data classes have also some special uses such as to create Picklists in Property Sheets.

Using Common Dialogs