Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Other ways to add items to an array

Tags:

arrays

delphi

Is there a way to fill a Delphi array using something like

array = array('this','that','and uh'); // php
array = ['this','that','and uh']; // javascript

Or if there's not, maybe you could give me a hint on what I'm trying to do:
I have this array of TButtons. I'm adding some buttons to the array, which should be visible to the user. Using this method of an array, I can easily use a loop to set their visibility property.

like image 299
Martin Avatar asked Dec 03 '22 04:12

Martin


1 Answers

With a dynamic array, and a suitably modern version of Delphi you can use an array constructor.

myArray := TArray<string>.Create('this', 'that', 'and uh');

If you want to create an array of buttons then it is written so:

buttons := TArray<TButton>.Create(btn1, btn2, btn3);

And then to iterate over the array of buttons:

for button in buttons do
  DoSomething(button);
like image 75
David Heffernan Avatar answered Dec 24 '22 18:12

David Heffernan