Local Properties

The 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.

Local properties are similar to local variables, but – just like Properties in a Type – can have getter and setter code associated with them that gets run when the value is read or written.

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 read and/or 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.

Please refer to the Properties topic in the Type Members section for a full discussion of properties and their capabilities.

Features of Local Properties

Local Property declarations can use all the features of Property type members in Classes and Records, including:


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;

See also