Read-Only Fields

When a field-declaration includes the ReadOnly modifier, this field is named a read-only field. Direct assignments to read-only fields can only occur as part of that field declaration or in a class constructor (instance or static constructor depending on the field type).

Attempting to assign a value to a read-only field or pass it as a reference or output parameter in any other context results in a compile error.

Example

Class ReadonlyField
    Readonly Public Ver: string;
    Readonly Public Id: string;
    
    Constructor ReadonlyField();
    Begin
        Ver := "1.0.0";
        Id := "ReadonlyField";
    End Constructor;
End Class;

Sub Test();
Var
    Obj: ReadonlyField = New ReadonlyField();
    s: string;
Begin
    s := Obj.Id + " " + Obj.Ver;
End Sub;

See also:

Fields