Search code examples
delphiarraysindexingdynamic-arrays

Delphi SetLength Custom Indexing


In Delphi, it is possible to create an array of the type

var
  Arr: array[2..N] of MyType;

which is an array of N - 1 elements indexed from 2 to N.

If we instead declare a dynamic array

var
  Arr: array of MyType

and later allocate N - 1 elements by means of

SetLength(Arr, N - 1)

then the elements will be indexed from 0 to N - 2. Is it possible to make them indexed from 2 to N (say) instead?


Solution

  • No, in Delphi dynamic arrays are always indexed from zero.