reflect.Value.valueOf

Creates a new reflect.Value object as a reference to the original variable.

Syntax

valueOf(
     val any-type )
  RETURNS reflect.Value
  1. val must be a variable, it cannot be an expression or literal.
    Note:

    The val parameter is passed by reference to the method.

  2. any-type can be of a various kind of types, except STRING.
    Note:

    The type of the variable cannot be STRING, use copyOf() instead.

Usage

The reflect.Value.valueOf() method returns a new reflect.Value object, which is a reference to the variable passed as parameter.

The reflect.Value object can then be used to call object methods to describe and modify the value.

The new reflect.Value object references the original variable: Any call to a reflection manipulation method modifies the underlying variable directly.

Exceptions:
  • The variable passed as parameter to the valueOf() method cannot be of type STRING. To create a reflect.Value object from a STRING variable, use the copyOf() method.

  • When passing a variable defined with a primitive type, the reflect.Value.valueOf() method returns a copy (like reflect.Value.copyOf()), instead of a reference. As result, changing the returned reflect.Value object will have no effect on the original variable.

Example

IMPORT reflect
MAIN
    DEFINE rec RECORD
               pkey INTEGER,
               name VARCHAR(50)
           END RECORD
    DEFINE val reflect.Value
    LET rec.pkey = 101
    LET rec.name = "Mike FITZPATRICK"
    LET val = reflect.Value.valueOf( rec )
    CALL val.getField(1).set(reflect.Value.copyOf(999))
    CALL val.getField(2).set(reflect.Value.copyOf("Scott PARS"))
    DISPLAY "rec pkey = ", rec.pkey
    DISPLAY "rec name = ", rec.name
END MAIN
Shows:
rec pkey =         999
rec name = Scott PARS