Assignments are distinguished as the following:

  • Simple assignment
  • Tuple assignment
  • Assignment as value
  • Assignment as reference

Simple Assignment

Assignments in PAscript are made with the = operator.

Target = Statement

Where Statement is a calculation, a constant, or a function call.

Example

Tuple Assignment

In PAscript functions can return tuples.

[var_1, var_2, ..., var_n] = functionCall ()

Example

Assignment as Value

When assigned as a value, a copy of the source value is written to the target value. If the source value then changes, the target value still contains the value it received when it was assigned.

Assignment as value is always used for simple data types such as numbers or text.

Note Up to and including PAtools 7.1, fields and value tables were also copied when <Field1> = <Field2> was assigned. This behavior has changed with PAtools 7.2: Starting with this version, fields and value tables are now assigned as references during equation (see following section).

Example

int32target=1
int32source=123
target=source  //  target has now value 123
source=5  //  target retains value 123
section globals
  texttext1, text2
endsection
text1="Hello"  //  text1 is assigned the value "Hello"
text2=text1  //  text2 is assigned the value "Hello"
text1="world"  //  text2 remains "Hello"

Assignment as Reference

When assigned as a reference, no copy of the source object is created, but the source object as a whole is assigned to the target object. If the value of the source object (or one of the values of the source object) changes, this automatically affects the value of the target object. An assignment as a reference is therefore equivalent to setting the target object as a pointer to the source object.

Note Global value tables cannot be overwritten in this way, the : copyFrom() command must be used.

Example

section globals
  variant[] table1
endsection
variant[10] _table2  //  Definition lokale Tabelle _table2

_table2=table1  /* Assignment as reference:
          _table2 is now a synonym for table1 */

table1:setText(0, "Hello")  /* The column 1 of table1 now also has assigned value 
"world */
// The column 1 of _table2 now also has the value "Hello"
_table2:setText(0, "world")  /* The column 2 von table1 now also has the value 
"world" */