MvREFERENCE#
Creates a reference from one variable to another, such that changes to one will appear to be made to the other. It can be also used to refer to a variable named created with an expression, like the miva_variable_value()
function.
Syntax
<MvREFERENCE NAME = "string: { expression } | literal"
INDEX="numeric: { expression } | literal"
MEMBER="string: { expression } | literal"
VARIABLE = "{ expression } | variable name">
Attributes#
Attribute | Description |
---|---|
NAME |
Required. Source Variable Name |
INDEX |
Optional. Index to the variable in NAME |
MEMBER |
Optional. Member to the variable in NAME |
VARIABLE |
Required. Target Variable Name or an expression that results in a variable name |
Note
INDEX
and MEMBER
refer to the variable in the NAME
parameter, NOT the VARIABLE
parameter.
Examples#
In its simplest form one variable can be directly referenced by another name.
<MvREFERENCE NAME = "g.global" VARIABLE = "l.local">
In typical usage a sub member of a structure or array can be referenced, simplifying programming syntax.
For this example assume an array of data like this:
l.products[1]:id = 27
l.products[1]:code = "polol042"
l.products[1]:name = "Polo Shirt"
item
.
<MvASSIGN NAME="l.posn" VALUE="{ 1 }">
<MvREFERENCE NAME = "l.prod" VARIABLE = "{ 'l.products[' $ l.posn $ ']' }">
The variable l.prod
now contains a reference to the array index such that l.prod:code
is the same as l.products[1]:code
. Using this in a loop results in clearer code.
<MvASSIGN NAME = "l.posn" VALUE = 1>
<MvASSIGN NAME = "l.last" VALUE = "{ miva_array_max(l.products)}">
<MvWHILE EXPR = "{ l.posn LE l.last }">
<MvREFERENCE NAME = "l.prod" VARIABLE = "{ 'l.products[' $ l.posn $ ']' }">
ID: <MvEVAL EXPR = "{ l.prod:id }"><br>
Code: <MvEVAL EXPR = "{ l.prod:code }"><br>
Name : <MvEVAL EXPR = "{ l.prod:name }"><br>
<MvASSIGN NAME = "l.posn" VALUE = "{ l.posn + 1 }">
</MvWHILE>