L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual

Page 1026

Advertising
background image

L-force | PLC Designer

Programming Reference

1024

DMS 4.1 EN 03/2011 TD29

Example of use:

ref_int REF= a; (* ref_int now points to a *)
ref_int := 12; (* a does now have the value 12 *)
b := ref_int * 2; (* b does now have the value 24 *)
ref_int REF= b; (* ref_int does now point to b *)
ref_int := a / 2; (* b does now have the value 6 *)
ref_int REF= 0; (* explicit initialization of the reference *)

Note: It is not possible to declare references like REFERENCE TO REFERENCE or ARRAY
OF REFERENCE or POINTER TO REFERENCE.
Note: With compiler version >= V3.3.0.0 references will be initialized (with 0).


Check for valid references
Operator "__ISVALIDREF" can be used to check whether a reference points to a valid
value, that is a value unequal 0.
Syntax:
<boolean variable> := __ISVALIDREF(<identifier declared with type REFERENCE TO
<datatype>);
<boolean variable> will be TRUE, if the reference points to a valid value, FALSE if not.
Example:
Declaration:

ivar : INT;
ref_int : REFERENCE TO INT;
ref_int0: REFERENCE TO INT;
testref: BOOL := FALSE;

Implementation:

ivar := ivar +1;
ref_int REF= hugo;
ref_int0 REF= 0;
testref := __ISVALIDREF(ref_int); (* will be TRUE, because ref_int points to ivar,
which is unequal 0 *)
testref0 := __ISVALIDREF(ref_int0); (* will be FALSE, because ref_int is set to 0 *)

Advertising