Assign Statements
The assign statements – expressed as :=, a colon followed by an equal sign – assigns the value of the expression on right to the writable expression on the left.
x := 5;
After the above statement, x has a value of 5.
Different from most other languages, Pascal and Oxygene purposely do not use the equal sign for assignment, to highlight the active nature of the statement – it is not expressing equality, but transferring a value (even if the end result – usually, but not always – is equality of the left and the right).
The left side of the assign statement must be a writable expression, while the right side can be any kind of Expression.
Writable expressions include:
- Local variables
- Field Access
- Property Access
- The
resultof the current method - Indexers for indexer properties or arrays
- Discardables (
nil) - Tuple Literals
Note that in particular for Properties with custom setter code, and for Discardables, the end result of an assignment is not necessarily equality. For example, a property setter (or getter) code might modify the actual value.
Other uses of the := Operator
The assignment operator can also appear in other statements that are not stand-alone assign statements such as:
varDeclaration Statements with an initializer- Field and Property declarations with an initializer
- Default Parameter values for Method declarations
- Property Initializers in
newExpressions for/toloopsusingstatementswithstatements
Notably, Consts use the = operator to specify their value, and not :=, since for constants, equality between the constant and the literal it is being initialized with is guaranteed, and a fundamental part of what makes them constants.
See Also
varDeclaration Statements with an initializer- Writable Expressions