dynAppend()

Appends y to the field x.

Synopsis

int dynAppend(<dyn_type> &x, <type> y|<dyn_type> &y );

Parameters

Parameter Meaning
x Field to which y is appended
y Value or dynamic field that is appended

Return Value

dynAppend() returns the length of the extended field x, -1 in the event of errors.

Errors

A message is issued in the event of missing or incorrect arguments or incorrect variable types.

Description

Appends y or all elements of y, provided that y is a dynamic field, to the field x. y may also be a dynamic field. In this case y is emptied and appended to x. y then does not contain any elements. The data type of y must match that of x if y is a dynamic field. If y is not a dynamic type, i.e. a simple value, y is converted automatically to the data type of x.

To append values without changing the source variable please refer to dynAppendConst().

Example

Adding 8 to the field {3,4,5,6,7}.

main()
{
  dyn_int x, y;
  x = makeDynInt(3,4,5,6,7);
  dynAppend(x, 8);
  DebugN(x);
}

Example

main()
{
  dyn_string dsDPE, dsValues;
  dyn_string dsNullValue = makeDynString("Null");
  dyn_anytype atValues;
  DebugN("First loop");
  for (int i = 1; i <= 5; i++)
  {
    dynAppend(dsDPE, "Value" + i);
    dynAppend(dsValues, dsNullValue );
  }
  //dynAppend(dynTarget, dynSource) will CUT (not copy) the array
  from dynSource, so the second loop uses an empty dyn_string (no
  elements)
  //To the second element anything is added -> the array
  dsNullValue is empty
  DebugN("dsDPE", dsDPE, "dsValues", dsValues, "dsNullValue",
  dsNullValue);
  /*
  ["dsDPE"][dyn_string 5 items
  1: "Value1"
  2: "Value2"
  3: "Value3"
  4: "Value4"
  5: "Value5"
  ]
  ["dsValues"]
  [dyn_string 1 items
  1: "Null"
  ]
  ["dsNullValue"]
  [dyn_string 0 items ]
  */
  DebugN("Second loop");
  for (int i = 1; i <= 5; i++)
  {
    dsDPE[i] = "Value" + i;
    dsValues[i] = dsNullValue;
  }
  //assign an empty dyn_string to a dyn_string -> the
  dyn_string will be casted to a string and added
  DebugN("dsDPE", dsDPE, "dsValues", dsValues);
  /*
  ["dsDPE"][dyn_string 5 items
  1: "Value1"
  2: "Value2"
  3: "Value3"
  4: "Value4"
  5: "Value5"
  ]
  ["dsValues"]
  [dyn_string 5 items
  1: ""
  2: ""
  3: ""
  4: ""
  5: ""
  ]
  */
  DebugN("Third loop");
  for (int i = 1; i <= 5; i++)
  {
    dsDPE[i] = "Value" + i;
    atValues[i] = dsNullValue ;
  }
  //an anytype can be anything, also an array, so each entry will
  be casted to an dyn_string (which is empty, due to first
  loop)
  DebugN("dsDPE", dsDPE, "dsValues", atValues);
  /*
  ["dsDPE"]
  [dyn_string 5 items
  1: "Value1"
  2: "Value2"
  3: "Value3"
  4: "Value4"
  5: "Value5"
  ]
  ["dsValues"]
  [dyn_anytype 5 items
  1: dyn_string 0 items
  2: dyn_string 0 items
  3: dyn_string 0 items
  4: dyn_string 0 items
  5: dyn_string 0 items
  ]
  */
  DebugN("Fourth loop");
  dsNullValue = makeDynString("AnEmptyValueNotNull");
  for (int i = 1; i <= 5; i++)
  {
    dsDPE[i] = "Value" + i;
    atValues[i] = dsNullValue;
  }
  //an anytype can be anything, also an array, so each entry will
  be casted to an dyn_string
  DebugN("dsDPE", dsDPE, "dsValues", atValues);
  /*
  ["dsDPE"]
  [dyn_string 5 items
  1: "Value1"
  2: "Value2"
  3: "Value3"
  4: "Value4"
  5: "Value5"
  ]
  ["dsValues"]
  [dyn_anytype 5 items
  1: dyn_string 1 items
  1: "AnEmptyValueNotNull"
  2: dyn_string 1 items
  1: "AnEmptyValueNotNull"
  3: dyn_string 1 items
  1: "AnEmptyValueNotNull"
  4: dyn_string 1 items
  1: "AnEmptyValueNotNull"
  5: dyn_string 1 items
  1: "AnEmptyValueNotNull"
  ]
  */
}

Assignment

Dynamic fields

Availability

CTRL