@ReadOnly

Specifies that a variable or property can supply a value, but cannot change its value.

Instructions

Combined modifiers
You cannot use @Shared together with @ReadOnly in the same statement.
Assignment operations
Code that uses a property with @ReadOnly cannot change its value. But code that has access to the reserved data can always change it.
You can assign a value to a variable with @ReadOnly only in a declaration or in a constructor procedure. The constructor must be in a class or structure that contains such a variable.

When to use @ReadOnly with a variable

There are conditions in which you cannot use the statement Const to declare and assign a constant value. For example, Const does not let you use a given data type, or you want to assign a value that cannot be calculated at compile-time.

Using @ReadOnly with reference types

If the data type of the variable is a reference type, for example, an array or a class instance, its members can change their values. Here @ReadOnly has almost no effect. It only prevents changes for which a new object replaces the initially assigned object. An example follows:

@ReadOnly Var characterArray() As Char = {`f`, `i`, `n`, `e`}
characterArray(2) = `r`

When initialized, the array referred to by characterArray() holds “f”, “i”, “n”, “e”. After the second line, characterArray() holds “f”, “i”, “r”, “e”.

Applicable to

Examples

TODO