Property Statement

Declares the names of properties and the procedures called when storing and retrieving values.

Syntax

One-line form

[ modifier ] Property declarator [ , declarator ]... [ Does trait_name . old_name ]

Many-line form

[ modifier ] [ Var ] Property declarator
[ Begin parameter_list ]
[ Get
    [ statements] ]
[ Set parameter
    [ statements] ]
End [ Property ]

Parts

modifier
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.
declarator
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.

Syntax

name [ ( [ dimensions ] ) ] [ As type | In unit ] [ = initializer ]
name
Necessary identifier or object handle
dimensions
Optional. One or more integer expressions separated by commas. Not permitted on unbacked properties.
type
Optional data type
unit
Optional unit of measure
initializer
Optional expression having a data type compatible with type or unit.
Var
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.
Begin
Optional in the many-line form. Allows you to specify that the property is an array.
parameter_list
Necessary after Begin. A list of integer parameters, separated by commas, which hold the array indices supplied by the caller.
Get
Marks the start of a procedure that is called when retrieving the current value of the property.
Set
Marks the start of a procedure that is called when storing a new value in the property.
parameter
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.
statements
Optional
End
Completes the many-line form. Alternatively, you can use End Property.

Instructions

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.

One-line form

The one-line form is always backed. A backed property automatically allocates memory with every instance of its owner.

Many-line form

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.

Examples

One-line property

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

See also