Icon SetLength

Unit: Internal

Available In: Client and Server Applications

procedure SetLength(var Value: array of <Type>; Length: Integer)

The SetLength procedure sets the length of the Value array input parameter. If extending the length of an array, all new elements are automatically set to nil for string, object, or method arrays, NaN (not a number) for numeric (Integer or Double) arrays, and False for boolean arrays.

Warning Arrays that are declared but not assigned a value are nil (Assigned function returns False) and not initialized. The SetLength procedure is one way of initializing them, even if they are initialized to a length of 0.

Examples

var
   X: array of String;
   I: Integer;
begin
   SetLength(X, 10);  // X now has a length of 10, but each element is still nil
   for I := 0 to Length(X)-1 do
      X[I] := '';  //  Initialize each array element with an empty string
end
Image