Using Caché Objects
Defining and Referring to Class Parameters
[Back] [Next]
   
Server:docs2
Instance:LATEST
User:UnknownUser
 
-
Go to:
Search:    

This chapter describes how to define class parameters and how to refer to them programmatically. It discusses the following topics:

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:
Defining Class Parameters
To add a class parameter to a class definition, add an element like one of the following to the class:
Parameter PARAMNAME;

Parameter PARAMNAME as Type;

Parameter PARAMNAME as Type = value;

Parameter PARAMNAME as Type [ Keywords ] = value;
Where
Parameter Types and Values
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.
The parameter types include BOOLEAN, STRING, and INTEGER. Note that these are not Caché class names. For a complete list, see Parameter Definitions in the Caché Class Definition Reference.
Except for the types COSEXPRESSION and CONFIGVALUE (both described in subsections), the compiler ignores the parameter types.
Class Parameter to Be Evaluated at Runtime (COSEXPRESSION)
You can define a parameter as an ObjectScript expression that it is evaluated at runtime. To do so, specify its type as COSEXPRESSION and specify an ObjectScript expression as the value:
Parameter PARAMNAME As COSEXPRESSION = "ObjectScriptExpression";
where PARAMNAME is the parameter being defined and ObjectScriptExpression is the ObjectScript content that is evaluated at runtime.
An example class parameter definition would be:
Parameter DateParam As COSEXPRESSION = "$H";
Class Parameter to Be Evaluated at Compile Time (Curly Braces)
You can define a parameter as an ObjectScript expression that it is evaluated at compile time. To do so, specify no type and specify the value in curly braces:
Parameter PARAMNAME = {ObjectScriptExpression};
where PARAMNAME is the parameter being defined and ObjectScriptExpression is the ObjectScript content that is evaluated at runtime.
For example:
Parameter COMPILETIME = {$zdatetime($h)};
Class Parameter to Be Updated at Runtime (CONFIGVALUE)
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: