Declares the names of properties and the procedures called when storing and retrieving values.
[ modifier ] Property declarator [ , declarator ]... [ Does trait_name . old_name ]
[ modifier ] [ Var ] Property declarator [ Begin parameter_list ] [ Get [ statements] ] [ Set parameter [ statements] ] End [ Property ]
- Optional. One of the following:
- Abstract – The property contains no implementation and must be overridden in a concrete subclass.
- Abstract Get – The property is read-only and its Get handler must be implemented in a concrete subclass.
- Abstract Set – The property is write-only and its Set handler must be implemented in a concrete subclass.
- Final – The property cannot be overridden in a subclass.
- Override – The property is a re-implementation of a property inherited from a superclass.
- Shared – The property is owned by the enclosing class and not an instance of that class.
- Necessary. One or more declarative clauses that have a similar syntax to the Dim statement.
The one-line form permits multiple declarators with commas between each.
name [ ( [ dimensions ] ) ] [ As type | In unit ] [ = initializer ]
- Necessary identifier or object handle
- Optional. One or more integer expressions separated by commas. Not permitted on unbacked properties.
- Optional data type
- Optional unit of measure
- Optional expression having a data type compatible with type or unit.
- Optional in the many-line form. Specifies that the property is backed.
- Not allowed in the one-line form, because this form is always backed.
- Optional in the many-line form. Allows you to specify that the property is an array.
- Necessary after Begin. A list of integer parameters, separated by commas, which hold the array indices supplied by the caller.
- Marks the start of a procedure that is called when retrieving the current value of the property.
- Marks the start of a procedure that is called when storing a new value in the property.
- Necessary after Set. It must be the same data type as the property. If you do not specify a data type, the type of the property is assumed.
- Completes the many-line form. Alternatively, you can use End Property.
A property, like a method, has public visibility. You may declare a property anywhere a method is permitted, namely, within modules, classes, and traits.
A property can have one of two forms: a one-line form or a many-line form.
The one-line form is always backed. A backed property automatically allocates memory with every instance of its owner.
The many-line form is usually not backed. A backed property automatically allocates memory with every instance of its owner. If you need a backed property, use the modifier Var.
Class Person Property Name As String End Class Person #person #person.Name = "John Doe" #Debug.PrintLine #person.Name
One-line array property
Class Person Const MaxAddresses = 2 Property Address(MaxAddresses) As String End Class
Many-line property, backed
Class Person Var Property Name As String Get ' do something Set value ' do something End Property End Class ' do something
Many-line property, not backed
Class Person Property Name As String Get ' do something Set value ' do something End Property End Class ' do something