Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

Push<T> class method

Project: Array Utilities Unit

Unit: DelphiDabbler.Lib.ArrayUtils

Record: TArrayUtils

Applies to: ~>0.1

class procedure Push<T>(var A: TArray<T>; const AValue: T);
  static;

Description

Appends a value to a given array

The length of the array is increased by one.

Parameters:

Example

This example appends three elements to a previously empty string array.

procedure Push_Eg;
var
  A, Expected: TArray<string>;
begin
  A := TArray<string>.Create();

  TArrayUtils.Push<string>(A, 'foo');
  Expected := TArray<string>.Create('foo');
  Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));

  TArrayUtils.Push<string>(A, 'bar');
  Expected := TArray<string>.Create('foo', 'bar');
  Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));

  TArrayUtils.Push<string>(A, 'baz');
  Expected := TArray<string>.Create('foo', 'bar', 'baz');
  Assert(TArrayUtils.Equal<string>(Expected, A, SameStr));
end;

See Also