property statement can be used to declare a property in the current scope. The property will be available for all code below its declaration, up until the end of the current scope – that is either to the end of the current method, if the variable is declared on that level, or to the end of the block Statement that includes the declaration.
In its simplest form, a property declaration starts with the keyword
property, followed by a new unique name for the property, a colon (
:), and the type. Declared as such, the property will behave the same as a Variable:
property i: Integer;
Distinct from variables, a property declaration can also provide a
write expression that will be executed when the property is accessed:
property i: Integer read SomeExpression write SomeOtherExpression;
Properties wit just a
read expression are read-only, while properties with just a
write statement are write-only. A property that provides both can be read and written.
The property's getter and setter code has access to everything that is in scope at the point of its declaration, including type members, as well as any local Variables, Contants, Methods or other local properties declared before it.
Features of Local Properties
- Indexer Properties
- Stored Properties (behave just like a Variable)
- Type Inference
Similar to type members, the following modifiers are allowed on local variables:
readonly— indicates that the property may not be altered after its declaration. For obvious reasons, this only makes sense for properties that have an initializer.
property i := 5; readonly;