Skip to main content
Previous section   Next section

InitialExpression

Specifies an initial value for this property.

Usage

To specify an initial value for this property, use the following syntax:

Property name As classname [ InitialExpression = initialexpression ];

Where initialexpression is a constant or an ObjectScript expression enclosed in curly braces.

Details

This keyword specifies an initial value for the property. This value is assigned by the %New() method of the class when a new instance is created. (If a property is transient, then its initial value is determined either by code invoked by %New() when the instance is created or by code invoked by %OpenId() when the instance is loaded from disk into memory.)

The value of the initial expression must be suitable for the given property type.

The expression can be arbitrarily complex, with the following limitations:

    The initial expression cannot refer to other properties. That is, an expression such as {..otherpropertyname} is not valid.

    The initial expression cannot instantiate an object and cannot include an object reference.

    The initial expression cannot invoke an instance method (only class methods).

    The initial expression must be specified in ObjectScript.

    The code executed by the expression should not report errors. InterSystems IRIS does not provide a way to handle errors returned by the expression.

    If the code executed by the expression causes other processing to occur, InterSystems IRIS does not provide a way to handle results of that processing.

Subclasses inherit the value of the InitialExpression keyword and can override it.

Default

The default value for the InitialExpression keyword is null.

Examples

The following shows several examples that use ObjectScript expressions:

Property DateTime As %Date [ InitialExpression = {$zdateh("1966-10-28",3)} ];

Property MyString As %String [ InitialExpression = {$char(0)} ];

/// this one is initialized with the value of a parameter
Property MyProp As %String [ InitialExpression = {..#MYPARM} ];

/// this one is initialized by a class method
Property MyProp2 As %Numeric [ InitialExpression = {..Initialize()} ];

See Also

Previous section   Next section