Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread How to declare a 2d array of integer?
Sun, Jul 27 2014 4:09 PMPermanent Link

Almanac

Avatar

Hi again. I'd like to get a simple 2d array, but no luck. Not in the help file...

I've tried Pascal declarations:
img_info: array[1..5, 1..15] of integer;
and
img_info: array of array of integer;

and even java (expected it to not work, but what the hey):
int[][] multD = new int[5][];

Thanks ahead for your help,
Alister.
Mon, Jul 28 2014 4:31 AMPermanent Link

Matthew Jones

Almanac wrote:

> Hi again. I'd like to get a simple 2d array, but no luck. Not in the
> help file...

I had a look at my source, and see that I implemented it "myself".
Basically,

img_info: array of integer;

....

SetLength(img_info, MAX_X * MAX_Y);


value = img_info[x + (MAX_X * y)];

You'd want to check your calculation is right, as I re-interpreted it
for this post. Basically, you allocate a single dimension and have the
values spread out. Like we did in the old days! Limitation of
Javascript and the decision to keep to that limit I guess.

--

Matthew Jones
Mon, Jul 28 2014 7:53 PMPermanent Link

Almanac

Avatar

Thank you Matthew. Actually the mapping of a 2d array onto 1 was my plan B, but I heard myself saying "Surely no. Ask." Sigh, it's "Surely yes, just sit back down at the keypunch machine, don't slip into old Fortran74 habits, and don't call me Shirley." Ah how the TRS80 and its cassette tape was a delight compared to the keypuncher! <grin>

Regards,
Alister.
Tue, Jul 29 2014 3:35 AMPermanent Link

Matthew Jones

Almanac wrote:

>  don't slip into old Fortran74 habits, and don't call me Shirley." Ah
> how the TRS80 and its cassette tape was a delight

Indeed, the restrictions of Javascript do bring some regression to our
lives. One wonders how the kids of today would think to work around a
single dimension array. Having watched that video about the quirks of
Javascript, and how writing it one way is good and another way is bad,
both having the same brackets etc, I'm very glad to have EWB to do the
smart translation.

--

Matthew Jones
Sat, Aug 2 2014 5:46 PMPermanent Link

Anders Westberg

Avatar

It is possible to use array of array in javascript which is essentially a 2D array. I expected this to work in EWB but a quick test failed Frown
Anders Westberg
Diginet AB
Mon, Aug 4 2014 4:18 AMPermanent Link

Matthew Jones

Anders Westberg wrote:

> It is possible to use array of array in javascript which is
> essentially a 2D array.

I think I looked at that, but in my experience as soon as you get to
anything beyond simle values you are better off creating an object and
using TObjectList.

--

Matthew Jones
Image