Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Init array of integer in delphi [duplicate]

Tags:

delphi

how to init an array like

TMyArray = array[1..2, 1..3] of Integer;

I tried

 MyArray  :  TMyArray;

 MyArray = ( (1,2,3),  (3,4,5) );

But did not have any luck with this style ...

like image 856
user1769184 Avatar asked Sep 20 '13 14:09

user1769184


1 Answers

You can initialise a typed constant as part of its declaration:

const
  MyArrayConst: TMyArray = (
     (1, 2, 3),
     (3, 4, 5)
  );

Or you can initialise a global variable in this way.

But you cannot initialise a local variable in that fashion. You could declare the constant, and then assign it to your variable.

var
  MyArray: TMyArray;
....
MyArray := MyArrayConst;
like image 172
David Heffernan Avatar answered Nov 15 '22 10:11

David Heffernan