Skip to main content

Arrays

Select an array type

Velox exposes four named one-dimensional dynamic-array types. Choose the type from the meaning of each element, not from the operation that happens to consume it.

TypeElementUse it forImportant boundary
TBytesByteBinary payloads, encoded data, files and stream transferIt is not text; decode or encode explicitly.
TIntegerArrayIntegerOrdered signed 32-bit valuesAn element value is independent of its zero-based index.
TStringArrayStringOrdered Unicode text valuesA blank element is different from an empty array.
TVariantArrayVariantHeterogeneous or dynamically typed valuesInspect Empty, Null and type state before conversion.

Shared runtime behavior

These are managed dynamic arrays implemented by the modified PascalScript runtime:

  • A newly initialized or cleared array has Length(A) = 0, Low(A) = 0 and High(A) = -1.
  • Valid indexes are always 0 .. Length(A) - 1. Iterate to High(A) only when the array is nonempty, or use a loop whose initial condition handles High(A) = -1.
  • SetLength(A, N) resizes in elements, preserves the common prefix, initializes newly added elements and finalizes removed managed elements.
  • Use SetLength(A, 0) to clear an array. The runtime silently treats a negative requested length as zero, but relying on that implementation quirk obscures intent.
  • Assignment shares the backing storage. Element writes through one assigned variable can therefore be observed through the other.
  • Changing the length of a shared array normally allocates a private copy. However, SetLength(A, Length(A)) is an early no-op in the current runtime and does not detach it.
  • Storage is reference-counted and released automatically. Do not use New, Dispose or pointer arithmetic to manage it.

When an independent copy is required, allocate the destination to the same length and copy each element explicitly. Do not use a same-length SetLength call as a copy operation.

Interchange rules

  • Treat array length and every external index as untrusted input. Check practical size limits before allocating or looping.
  • A const parameter prevents reassignment through that parameter but is not a promise that every other alias is immutable.
  • A var parameter can replace or resize the caller's array. Review the called function's contract before assuming existing elements survive.
  • Serialize with an explicit representation. A TBytes value needs a binary encoding such as Base64 for text-only formats; string, integer and Variant arrays need element-level null/type rules.
  • Do not persist implementation pointers or rely on reference counts. They are runtime internals, not a script-visible data contract.

External references

Created 2026-07-15