user41758
user41758

Reputation: 343

Runtime Arrays using Create

Say i have

ArrayOfTXSDecimal = array of TXSDecimal;

Then during runtime i do

Ids := ArrayOfTXSDecimal.create(14450);

What did i just create? an array(ids) with 14450 indexs or just index 14450

Upvotes: 0

Views: 175

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596156

You are creating a dynamic array with one element whose value is 14450. You are doing the equivalent of this:

SetLength(Ids, 1);
Ids[0] := 14450;

This Create() syntax for dynamic arrays is documented on Embarcadero's DocWiki:

An alternative method of allocating memory for dynamic arrays is to invoke the array constructor:

type
  TMyFlexibleArray = array of Integer;

begin
  MyFlexibleArray := TMyFlexibleArray.Create(1, 2, 3 {...});
end;

which allocates memory for three elements and assigns each element the given value.

Upvotes: 5

Related Questions