Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is TArray<T>.Create() documented somewhere?

It was just by chance when I found out that a construct like this actually compiles and produces the desired result:

var
  Arr: TArray<Integer>;
begin
  Arr := TArray<Integer>.Create(100, 101, 102);
end;

I only tested it in Delphi XE, but it may work in older versions, too. Is this documented somewhere?

like image 683
Uwe Raabe Avatar asked Apr 14 '11 10:04

Uwe Raabe


2 Answers

It's documented in the language guide.

like image 170
David Heffernan Avatar answered Oct 21 '22 12:10

David Heffernan


It's a generic version of the following, which works as far back as Delphi 2007:

type
  TIntArray = array of Integer;

var
  MyIntArray: TIntArray;
begin
  MyIntArray := TIntArray.Create(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
  ...
end;

It's finally a solution to being able to initialize an array without knowing the size first.

like image 43
Ken White Avatar answered Oct 21 '22 11:10

Ken White