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:
DEFINE_COM class(#SALARY) name(#SALARY)
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. |
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. |
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. |
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:
DEFINE_COM class(#GIVENAME) name(#USER_GIVENAME)
DEFINE_COM class(#EMPNO) name(#LAST_EMPNO)
DEFINE_COM class(#SALARY) name(#SALARY)
DEFINE_COM class(#SALARY) name(#OLD_SALARY)
DEFINE_COM class(#SALARY) name(#NEW_SALARY)
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:
DEFINE_COM class(#PRIM_ALPH) name(#MYSTRING)
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:
DEFINE_COM class(#PRIM_NMBR) name(#MYNUMBER)
The primitive data classes have also some special uses such as to create Picklists in Property Sheets.
Using Common Dialogs