reflect.Value.canAssignToVariable

Checks if this reflect.Value can be assigned to a variable.

Syntax

canAssignToVariable(
     var any-type )
  RETURNS BOOLEAN
  1. var is a program variable.
  2. any-type can be of a various kind of types.

Usage

The canAssignToVariable() method returns TRUE, if the current reflect.Value object references a value that can be assigned to the variable passed as parameter.

For example, it is not possible to assign a structured RECORD to a variable defined with a primitive type such as STRING.

This method is typically used to check that a target variable can be assigned with the assignToVariable() method.

Example

IMPORT reflect
MAIN
    DEFINE r1, r2 RECORD pkey INTEGER END RECORD
    DEFINE val reflect.Value
    DEFINE s STRING
    LET val = reflect.Value.valueOf(r1)
    IF NOT val.canAssignToVariable(s) THEN
        DISPLAY "Cannot assign r1 to s..."
    END IF
    IF val.canAssignToVariable(r2) THEN
        DISPLAY "Assigning r1 to r2..."
        CALL val.assignToVariable(r2)
    END IF
END MAIN
Shows:
Cannot assign r1 to s...
Assigning r1 to r2...