Board index » delphi » Help! array of type array

Help! array of type array

Can anyone tell me how to phrase a reference to the first element of
the fifth element of an array X of type array?   would it be X[5][1]?

Thanks,
everh...@midamer.net

 

Re:Help! array of type array


Quote
In article <318a128...@wind.midamer.net>, everh...@midamer.net (Dan) writes:
>Can anyone tell me how to phrase a reference to the first element of
>the fifth element of an array X of type array?   would it be X[5][1]?

Yes, that ought to work, so should X[5,1].  

If you're declaring your arrays like so:

type
  MyArrayType = array [1..10] of array [1..10] of SomeType;

you might care to use the following alternative shorthand declaration
syntax

type
  MyArrayType = array [1..10, 1..10] of SomeType;

Which produces the same data structure.

Quote
>Thanks,
>everh...@midamer.net

HTH

-* Stephen *-
Stephen Posey
University of New Orleans
Email  : S...@uno.edu
WWW    : http://www.uno.edu/~slp

Re:Help! array of type array


In a previous article, everh...@midamer.net (Dan) wrote:

Quote
>Can anyone tell me how to phrase a reference to the first element of
>the fifth element of an array X of type array?   would it be X[5][1]?

>Thanks,
>everh...@midamer.net

You seem to have figured it out for yourself.

What I am wondering about is ..
   Why use an array of arrays instead of a multi-dimensional array?
It may be just a matter of personal preference, but I find it a lot
easier to understand what I am doing with arrays when I use
multi-dimensional arrays - particularly since the vast majority of
times I use a multi-dimensional array I use it to store a matrix.
The simpler notation for referencing the elements of the
multi-dimensional arrays helps a lot too.

Ie.,
   Instead of "Var X: array[A..B] of array[C..D] of SomeType;"
   Why not    "Var X: array[A..B, C..D] of SomeType;"   ?

In your case, the X[1][5] notation is used, in the this two-dimensional
array example,    X[1,5] would be used.

Rob

Re:Help! array of type array


How did you declare the array??

If you declared it like this:

matrix:  Array [1..5, 1..5] of integer;

or

matrix:  array [1..5] of array [1..5] of integer;

then you'd just use matrix[5,1].

The compiler interprets the second declaration type the same way as the first.

Ken

In article <318a128...@wind.midamer.net>, everh...@midamer.net says...

Quote

>Can anyone tell me how to phrase a reference to the first element of
>the fifth element of an array X of type array?   would it be X[5][1]?

>Thanks,
>everh...@midamer.net

--
Views expressed herein are not necessarily the views
of Ontrack Computer Systems, Inc. or Ontrack Data Recovery, Inc.
*******************************************************************
* Ken Stieers               |  Minneapolis - 1.800.872.2599       *
* AV Research/Apps. Eng.    |  Los Angeles - 1.800.752.7557       *
* Ontrack Computer Systems  |  Washington, D.C. - 1.800.650.2410  *
* Ontrack Data Recovery     |  London - 0800 24 39 96             *
* Eden Prairie, MN          |  Japan - 81.429.32-6365             *
*******************************************************************

Re:Help! array of type array


Quote
Dan (everh...@midamer.net) wrote:

: Can anyone tell me how to phrase a reference to the first element of
: the fifth element of an array X of type array?   would it be X[5][1]?

: Thanks,
: everh...@midamer.net

Dan,
        to declare a two dimensional array, you would simply go:

var
  ThisArray : array[1..10,1..8] of byte(string, char, etc);

and it's that simple. the only thing which could confuse you is the fact
that the Y value comes first. then X.. like if you were making a letter
with this,

const
  O : array[1..10, 1..10] of byte = (
        (0,1,1,1,1,1,1,1,1,0),
        (1,1,1,1,1,1,1,1,1,1),
        (1,1,0,0,0,0,0,0,1,1),
        (1,1,0,0,0,0,0,0,1,1),
        (1,1,0,0,0,0,0,0,1,1),
        (1,1,0,0,0,0,0,0,1,1),
        (1,1,0,0,0,0,0,0,1,1),
        (1,1,0,0,0,0,0,0,1,1),
        (1,1,1,1,1,1,1,1,1,1),
        (0,1,1,1,1,1,1,1,1,0));

this would make a two dimensional array O, of bytes. the value 1
represents on, and 0 off. i use this for graphics sometimes, and is
useful in screen savers. how you would display the O to the screen is:

(assuming you have all the graphics modes set, and a putpixel proc)

var
  x, y : integer;

begin
  (init graphics mode)
  for y := 1 to 10 do begin    { why Y first? because  array[y, x] }
    for x := 1 to 10 do begin
      PutPixel(x, y, color); { or however the PutPixel's parameters are }
    end;
  end;
end.

you must do the y first because unlike graphing co-ordinates, the higher
dimension goes first, i.e Y over X, or Z over Y, like [z, y, x], etc..

i hope this helps.

victor dods

Re:Help! array of type array


-=[ In:everh...@midamer.net was heard to say... ]=-
 In> Can anyone tell me how to phrase a reference to the first element of
 In> the fifth element of an array X of type array?   would it be X[5][1]?

 In> Thanks,
 In> everh...@midamer.net

Looks okay to me. Why not just try it in a test program if you're not sure?

        -- Kim Forwood --

  /-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\
  $           Kim Forwood  <kim.forw...@access.cn.camriv.bc.ca>          %
  %         For what purpose is life, if one cannot live freely?         $
  \-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/

___ Blue Wave/QWK v2.20

Re:Help! array of type array


Quote
Dan (everh...@midamer.net) wrote:
> Can anyone tell me how to phrase a reference to the first element of
> the fifth element of an array X of type array?   would it be X[5][1]?
> Correct !

Look at it a bit differently: try using two types of indices, for example:

type
  ar1 = array [1..10] of integer;
  ar2 = array ['a'..'j'] of ar1;
var
  X : ar2;

X's elements are arrays so the fifth element
of array X is the array X['e'].
The first element of this element is then X['e'][1].

Shai.
 8)

Other Threads