Built-in variables: value

Strictly speaking, value is not a real built-in variable but a hidden parameter available exclusively in all onset methods. It contains the value being assigned to a property, the respective onset method is associated with. As such the data type of the value does correspond to the type of the property.

Declaration

data‑type‑of‑the‑property value

Discussion

By using the variable value the implementation of the onset method can evaluate, validate and convert the just assigned property value. As such value is valid only within the implementation of an onset method.

You can use the variable value within expressions inside an onset method wherever an operand of the data type matching the declaration of the original property is allowed. Usually, you do it in order to store the just assigned value in the properties internal pure memory. Assuming, you have a GUI component with a property called Level, then the following code stores the new value in this properties memory:

pure Level = value;

However, the typical implementation of an onset method validates in the first step the value variable and in the second step compares it with the current content of the property. In this manner you can optimize your GUI component implementation. Assuming, the above property Level is declared as an int32 data type and its valid values should lie in the range 0 .. 100:

// First validate the new value if ( value < 0 ) value = 0; if ( value > 100 ) value = 100; // Then compare the new value with the current content of the property if ( value == pure Level ) return; // The value is different. pure Level = value; // Force the component to be updated InvalidateViewState();