Property Statement

Declares the names of properties and the procedures used to change and return values.

Syntax

One-line construct

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

Block construct

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

Parts

modifier
Optional
  • @Abstract – The property contains no implementation and must be overridden in a concrete child class. Only applicable in an abstract class or trait.
  • @Backed – The property is backed. The one-line construct is always backed.
  • @Deprecated – The property is deprecated. See @Deprecated for more information.
  • @Open – The property can be overridden in a child class. Only applicable in an open class.
  • @Override – The property is a re-implementation of a property inherited from a parent class.
  • @ReadOnly – The property is read-only. It must return the value with Get. It cannot change the value with Set.
  • @Shared – The property is owned by the enclosing class and not an instance of that class.
  • @WriteOnly – The property is write-only. It must change the value with Set. It cannot return the value with Get.
You can put @Abstract together with @ReadOnly or @WriteOnly. You can put @Backed and @Deprecated together with all other modifiers.
declarator
Mandatory one or more declarations that have a similar syntax to the statement Dim. The one-line construct lets you write several declarators with a comma between each.

Declarator

name [ ( [ dimensions ] ) ] [ As type | In unit ] [ = initializer ]
name
Mandatory name.
dimensions
Optional one or more integer expressions with a comma between each. Not permitted with unbacked properties.
type
Optional data type
unit
Optional unit of measure
initializer
Optional expression with a data type compatible with type or unit.
Begin
Optional in the block construct. Lets you specify that the property is an array.
parameter_list
Mandatory after Begin, a list of integer parameters, with a comma between each, which hold the array indices supplied by the caller.
Get
Identifies the start of a block of code that returns the value of the property.
Set
Identifies the start of a block of code that changes the value of the property.
parameter
Mandatory after Set. It must be the same data type as the property. If you do not specify a data type, then the compiler uses the type of the property.
statements
Optional executable statements
End
Completes the block construct. You can also use End Property.
You can change this part of the syntax. See @Option Directive for more information.

Instructions

A property has many of the same qualities as a method. A property has public visibility. You can declare a property in libraries, classes, and traits.

A property can have one of two constructs: a one-line construct or a block construct.

One-line construct

The one-line construct is always backed. Thus it automatically allocates memory with each instance of its owner.

Block construct

The block construct is usually not backed. Thus it does not automatically allocate memory with each instance of its owner. If necessary, then use the modifier @Backed.

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

Block property, backed

Class Person
   @Backed Property Name As String
      Get
         ' do something
      Set value
         ' do something
   End Property
End Class

' do something

Block property, not backed

Class Person
   Property Name As String
      Get
         ' do something
      Set value
         ' do something
   End Property
End Class

' do something

See also