When viewing this book online, use the preface of this book to quickly find other topics.

Introduction to Class Parameters

A class parameter defines a special constant value available to all objects of a given class. When you create a class definition (or at any point before compilation), you can set the values for its class parameters. By default, the value of each parameter is the null string, but you can specify a non-null value as part of the parameter definition. At compile-time, the value of the parameter is established for all instances of a class. With rare exceptions, this value cannot be altered at runtime.

Class parameters are typically used for the following purposes:

To customize the behavior of the various data type classes (such as providing validation information).

To define user-specific information about a class definition. A class parameter is simply an arbitrary name-value pair; you can use it to store any information you like about a class.

To define a class-specific constant value.

To provide parameterized values for method generator methods to use. A method generator is a special type of method whose implementation is actually a short program that is run at compile-time in order to generate the actual runtime code for the method. Many method generators use class parameters.

Defining Class Parameters

To add a class parameter to a class definition, add an element like one of the following to the class:

PARAMNAME is the name of the parameter. Note that by convention, parameters in Caché system classes are nearly all in uppercase; this convention provides an easy way to distinguish parameters from other class members, merely by name. There is no requirement for you to do the same.

It is not necessary to specify a parameter type, but if you do, this information is primarily meant for use by the development environment. The Class Inspector in Studio uses the parameter type to provide suitable options and validation. For example, if a parameter is of type BOOLEAN, the Class Inspector provides the choices 0 and 1.

You can define a parameter so that it can modified outside of the class definition. To do so, specify its type as CONFIGVALUE. In this case, you can modify the parameter via the $SYSTEM.OBJ.UpdateConfigParam() method. For example, the following changes the value of the parameter MYPARM (in the class MyApp.MyClass) so that its new value is 42:

set sc=$system.OBJ.UpdateConfigParam("MyApp.MyClass","MYPARM",42)

Note that $SYSTEM.OBJ.UpdateConfigParam() affects the generated class descriptor as used by any new processes, but does not affect the class definition. If you recompile the class, Caché regenerates the class descriptor, which will now use the value of this parameter as contained in the class definition, thus overwriting the change made via $SYSTEM.OBJ.UpdateConfigParam().

Referring to Parameters of a Class

To refer to a parameter of a class, you can do any of the following:

Within a method of the associated class, use the following expression:

..#PARMNAME

You can use this expression with the DO and SET commands, or you can use it as part of another expression. The following shows one possibility:

set object.PropName=..#PARMNAME

In the next variation, a method in the class checks the value of a parameter and uses that to control subsequent processing: