Assignment Statement

An assignment statement assigns a new value to a variable, a property, or an event.

assigment-statement:

variable-assignment

event-assignment

event-assigment:

event   :=   expression

event   +=   expression

event   -=   expression

An assignment statement has two forms: simple assignment and event assignment.

Simple Assignment

The left part of a simple assignment statement must be an expression, which value is a variable, a property, or an event. The right part of the statement must be an expression of a type that is compatible with the variable type, that is, there should be an implicit conversion from the expression type to the variable type. Otherwise, a compile error occurs.

variable-assignment:

variable   :=   expression

If the left part of the statement is a property, the Set access method should be determined for this property. Otherwise, a compile error occurs.

The statement is executed as follows:

If this variable is a delegate type, the assignment is executed in the same way as in event assignment. Setting the invocation list (:=) for delegate-type variables, unlike for events, is available in any location of the code.

Event Assignment

The left part of an event assignment statement must be an expression classified as an event access. The right part of an assignment statement must be an expression that can be implicitly converted to the type of the event, or Null if event processing is to be cancelled.

event-assigment:

event   :=   expression

event   +=   expression

event   -=   expression

An event assignment statement can have either of the three forms:

The operator is executed as follows:

Example

Delegate UserEvent(x, y: integer);

Class TestAssignment
    s: string;
    
    Property Text: string
        Get
        Begin
            Return s;
        End Get
        Set
        Begin
            //Variable assignment
            s := value;
        End Set
    End Property;
    
    Event OnUserEvent: UserEvent;
    
    Constructor Create(s: string);
    Begin
        //Property assignment
        Self.Text := s;
        //Event assignment
        OnUserEvent := EventSub1;
        OnUserEvent += EventSub2;
    End Constructor;

    Sub EventSub1(x, y: integer);
    Begin
        
    End Sub;
    
    Sub EventSub2(x, y: integer);
    Begin
        
    End Sub;
End Class TestAssignment;

See also:

Statements