reflect.Value.valueOf
Creates a new reflect.Value
object as a reference to
the original variable.
Syntax
valueOf(
val any-type )
RETURNS reflect.Value
- val must be a variable, it
cannot be an expression or literal.Note:
The val parameter is passed by reference to the method.
- any-type can be of a various kind of types, except
STRING
.Note:The type of the variable cannot be
STRING
, usecopyOf()
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.
-
The variable passed as parameter to the
valueOf()
method cannot be of typeSTRING
. To create areflect.Value
object from aSTRING
variable, use thecopyOf()
method. -
When passing a variable defined with a primitive type, the
reflect.Value.valueOf()
method returns a copy (likereflect.Value.copyOf()
), instead of a reference. As result, changing the returnedreflect.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
rec pkey = 999
rec name = Scott PARS