Adding Elements
SetLength(array, numberOfElements)
SetLength
. This function adds a number of nil
elements simultaneously:
x := [15, "xyz", {a: 2, b: 3}]; SetLength(x, 10);After
SetLength
has executed, x
has ten elements; the last seven are nil
.
SetLength
to specify the array's final size, and then assign each element with [ ]
. This makes sense when you realize that each call to AddArraySlot
requires a new memory allocation, while using SetLength
requires it only once.
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996