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?
It's documented in the language guide.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With