Support for “readonly” class fields has been added to DWScript repository.
The syntax is similar to the one in Oxygene, with a qualifier following a field declaration:
type TTest = class FField : Integer; readonly; end;
A field marked as readonly can only be assigned at declaration or in a constructor of the class.
Note that “readonly” is a contextual keyword, you can still have fields named “ReadOnly” if you want to, so there should be no compatibility issues with existing code. If several fields are declared together, the readonly qualifier will apply to all of them:
FImReadOnly, FImReadOnlyToo : Integer; readonly; FAndMeAsWall : Integer := 123; readonly;
This is a relatively minor language change which was motivated to allow marking readonly fields when declaring JavaScript objects for SmartPascal / OP4JS, though it can have other uses as well.