Date: Thu, 28 Mar 2024 11:50:58 +0100 (CET) Message-ID: <177125583.111022.1711623058601@srvdoc.doc.ipesoft.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_111021_1655450844.1711623058601" ------=_Part_111021_1655450844.1711623058601 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Using local variables allows to effectively implement loops, subprograms=
and other control algorithms.
The identifier of a local variable is a sequence of characters, which can =
be used for the name of D2000 system (rules for object name definition). It must begin wit=
h the character "_" (underscore). For example: _i, _i1, _locVar.1. Maximum:=
64 characters. Value of a local variable is characterized by all value att=
ributes as well as objects in D2000 system (time, limits, process alarm etc=
.).
Available types of local variables:
The objects SD.RecordDef and SV.Structure are used for a demonstration of = some features of local variables.
Local variable definition is denoted by its type (in case of RECORD and =
ALIAS type, by the type of the structure), which is followed by the local v=
ariable identifiers of that type, separated with commas, e.g.:
INT _a, _b, _c,
or
RECORD NOALIAS (SD.RecordDef) _rec1, _rec2.
TIME represents also a key word in assignment.
Variables of INT, BOOL, REAL, TIME a = TEXT types represent simple values of given type.
Variables of TEXT type are internally encoded in UTF-8.
A variable of ALIAS type represents a r= eference to a D2000 system object. After running the script, the reference = is empty and its value is not defined. It is not possible to use such a var= iable and the error _ERR_NO_ASSIGNED_ALIAS, which causes interruptio= n of the script execution, will be generated, if you attempt to do it. Afte= r initialization of such a variable (setting the reference to an object), i= t acquires the value of the linked object by means of particular action (SET AS). It is possi= ble to use such a variable in an expressions, or to assign a value to it in= the same way as if a linked object was used.
Example:
ALIAS _obj
INT _i=
_obj :=3D 1 ; action will cause <=
i>ERR_NO_ASSIGNED_ALIAS error
ALIAS _obj
INT _i=
SET _obj AS U.Int
_obj :=3D 1 ; assigns the value of 1 the user vari=
able U.Int
WAIT =
; wait for execution of the assignment
_i=
:=3D _obj ; assigns the value of U.I=
nt to the local variable _i
If an ALIAS type local variable is linked with an object of Value array type, it allows to = use indexing in the same way as for the object of Value array type:
Example:
ALIAS _obj
INT _i=
SET _obj AS X.Array
_i :=3D <=
span>_obj[2] ; assigns the value of the second ite=
m of X.array to local variable _i
There are two different types of ALIAS= i> type local variables:
When you declare a typed ALIAS it is necessary to specify a type (in our= case, it is an object of Structure definition type), which limits the set of possible object= s (of Structured variab= le type), to which the local variable (typed ALIAS) may be linked. For = a local variable declared in this way, it is able, in expressions (of cours= e, after an association using SET AS action), to use indexing and to access items in the sam= e way as for object of = Structured variable type.
Example:
ALIAS (SD.RecordDef) _recAlias
INT _i
_i :=3D 2
ALIAS _re=
cAlias AS SV.Structure
_recAlias[_i]^Int :=3D 1
The variable of RECORD type allows to c= reate a local variable of Record type. The structure type is given b= y the object of Struct= ure definition type, which is declared. If RECORD variable is a formal = parameter, its structure type - non-typed RECORD need not be set.
Example:
RECORD (SD.RecordDef) _recLocal
After running the script, the array size of such a local variable define= d in this way is one (1) and the values of all the items are invalid.
Example: Assigning a value
RECORD (SD.RecordDef) _recLocal
_recL=
ocal[1]^Text :=3D "text value"
_recLocal[1]^Int :=3D 8
Change of the array size of a local variable may be executed by using REDIM action.
Example: Change the array size to ten (10) items
REDIM _recLocal [10]
Minimum array size is zero (0). An array size change doesn't lose values=
of items contained in the array before the action. Potential new items cre=
ated are initialized to invalid value.
An item of local variable of Record type (or object of Structured variable type=
) may be Object type (see the topic Structure definition). Such an item is interpreted=
in the script as an untyped ALIAS. Consequence:
Assignment:
_recLocal[1]^Object :=3D 1
may cause the error _ERR_NO_ASSIGNED_ALIAS if an object is not li= nked to an item. Assignment of an object to item is identical with assignme= nt of variables of ALIAS type:
SET _recLocal[1]^Object AS U.Int<= /p>
Note: Analogous to untyped ALIAS, the access to an item of a loca= l variable that is not linked with will generate the error _ERR_NO_ASSIG= NED_ALIAS.
To avoid this behaviour use the keyword NOALIAS when you declare the loc= al variable.
RECORD NOALIAS (SD.RecordDef) _recLocal
For a local variable declared this way, all items of Object type = are interpreted as standard values of any type (INT, BOOL, REAL, TEXT, TIME= ). Therefore the following declaration is correct:
_recLocal[1]^Object :=3D 1
_recLocal[1]^Obj=
ect :=3D "TEXT"
The item Object changes its own type together with individual ass=
ignments.
After assigning a value to an Object type item of Structured variable type object, thi=
s assignment is automatically redirected to the linked object (likewise unt=
yped ALIAS). If the item is not linked to an object, an error will occur on=
ly if the action WAIT follows.
ESL allows to assign either a whole structure row or a whole structure a= t once. This assignment is executed by SET WITH action.
Action syntax:
SET identDst_Rec WITH identSrc_Rec
where
Both identifiers must represent a structure row or a whole structure<= /i>. Structure types must be the same (the error: Incompatible types= ). In case of a whole structure, their number of rows must be identical (th= e error: _ERR_RANGE_ERROR). The action will assign all the values fr= om the source (identSrc_Rec) to the destination (identDst_Rec).
!!! IT DOES NOT CHANGE THE ASSOCIAT= ED (LINKED) OBJECTS IN INDIVIDUAL ITEMS !!!.
SET AS action = permits to assign and change linked objects (for items of Object typ= e) in a whole structure row, or in a whole structure together.
Action= syntax:SET identDst_Rec AS identSrc
The same limits as listed for the action SET WITH are also available for identSrc and identD=
st, but they may not be local variables of Record type declared =
as NOALIAS.
Permitted combinations of identSrc and =
identDst parameters for SET WITH a SET AS actions.
SET BIND=
b> action links a row of a local variable of Record type to a=
row of an object of St=
ructured variable type.
Action syntax:
SET _recLocal_Row BIND struct_Row=
where
SET _recLocal[2] BIND SV.Structur= e[1]
After the action execution, the values of all the items of the row 2 of =
the local variable (_recLocal[2]) are the same the values of the row 1 of t=
he object SV.Structure. For example: the expression _recLocal[2]^Int=
returns the same value as the expression SV.Structure[1]^Int.
The feature of row binding is also allowed for other actions:
Example: Assigning a value
_recLocal[2]^Int :=3D 1
will assign the value of 1 to the item SV.Structure[1]^Int. Since the va=
lue of the item _recLocal[2]^Int copies the value of the item SV.Structure[=
1]^Int, any change of the local variable is executed after a change in SV..=
. object (it is possible to use WAIT=
a> action). Behaviour of rows of a local variable Record type, which=
are not linked (SET BIND) to =
another row, is unchanged (described above).
Each row of the local variable _recLocal may be linked to another (=
or the same) row of an object of Structured variable type. The only limitation is, that local =
variable and object must be of the same structured type (structure definition).
Unlinking a row (cancelling the action SET BIND) is allowed by the action:
SET _recLocal[2] BIND NONE
All values of items will acquire undefined state.
Related pages: