The accessor of a property contains the executable operators associated with reading and writing the property value.
inline-accessor-declarations:
inline-get-accessor-declaration inline-set-accessor-declarationopt
inline-set-accessor-declaration inline-get-accessor-declarationopt
inline-get-accessor-declaration:
attributesopt Get method-localsopt Begin block End Get
inline-set-accessor-declaration:
attributesopt Set method-localsopt Begin block End Set
The accessor declarations can contain a declaration of the reading method, writing method, or both. Each declaration consists of the Get or Set keyword and declaration body.
The property value reading method corresponds to the method that returns values of the type corresponding to the property type. The set of the method parameter corresponds to the property parameter set.
The method of setting (writing) property value corresponds to the method that does not return a value. The parameter list for this method is determined by adding a property parameter list to the additional value parameter with the type matching the field type. This parameter is named Value and is declared implicitly. Using the Value name as a property parameter name or local variable name declared in the writing method is a compile error.
The compiler automatically generates reading and writing methods and reserves specific names for these methods.
Depending on the presence of reading or writing accessors in the property declaration, it is classified as follows:
A property that includes both a get accessor and a set accessor is said to be a read-write property.
A property that has only a get accessor is said to be a read-only property. It is a compile error for a read-only property to be the target of an assignment.
A property that has only a set accessor is said to be a write-only property. Except as the target of an assignment, it is a compile error to reference a write-only property in an expression.
Class TestProperty
i: integer;
//Property available for reading and writing
Public Property Prop1: integer
Get
Begin
Return i;
End Get
Set
Begin
i := Value;
End Set
End Property;
//Read-only property
Public Property Prop2: integer
Get
Begin
Return 1
End Get
End Property;
//Write-only property
Public Property Prop3: integer
Set
Begin
i := Value;
End Set
End Property;
End Class;
See also: