Adding Elements

SetLength


SetLength(array, numberOfElements)


If you need to add a number of elements, you should use 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.


Note:If you are adding a number of elements to an array, it is quicker to use 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