procedure SetLength(var S: <string or dynamic array>; NewLength: Integer);
Sets the length of a string or dynamic array variable.
S is a Delphi string or dynamic array variable.
NewLength is the new number of characters or elements in
For a short string variable, SetLength simply sets the length-indicator character (the character at S) to the given value. In this case,
NewLength must be a value from 0 through 255.
For a long string variable, SetLength reallocates the string referenced by
S to the given length. Existing characters in the string are preserved, but the content of newly allocated space is undefined.
For a dynamic array variable, SetLength reallocates the array referenced by
S to the given length. Existing elements in the array are preserved and newly allocated space is set to 0 or nil. For multidimensional dynamic arrays, SetLength may take more than one-length parameter (up to the number of array dimensions). Each parameter specifies the number of elements along a particular dimension.
Following a call to SetLength,
S is guaranteed to reference a unique string or array -- that is, a string or array with a reference count of one. If there is not enough memory available to reallocate the variable, SetLength raises an EOutOfMemory exception.