Results 1 to 5 of 5

Thread: Multidimensional Arrays?

  1. #1
    Join Date
    Jan 2012
    Posts
    64
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Multidimensional Arrays?

    How do I do multidimensional arrays?

    Like.. I want to do a 2D or 3D array, how would I do that?
    I tried googling it and got

    Code:
    Var
    my2DArray : Array[1..3][1..5] of Byte;
    Begin
     my2DArray[2][4] := 10;
    End
    but apparently that doesn't compile because its expecting an 'of' between [1..3] and [1..5]

  2. #2
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Needs to be like this:

    Simba Code:
    var
      my2DArray: array[1..3] of array[1..5] of Byte;

    begin
     my2DArray[2][4] := 10;
    end.

  3. #3
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    I'm wondering what you're using this for haha.

  4. #4
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    By the way, I recommend you use something like this:

    Simba Code:
    var
      my2DArray: array[1..3] of array of Byte;
      a, b, c: Integer;

    begin
      ClearDebug;
      my2DArray[1] := [0, 1, 2, 3, 4];
      my2DArray[2] := [5, 6, 7, 8, 9];
      my2DArray[3] := [10, 11, 12, 13, 14];
      // Lets print it:
      for a := 1 to 3 do
      begin
        c := High(my2DArray[a]);
        for b := 0 to c do
          WriteLn('my2DArray[' + IntToStr(a) + '][' + IntToStr(b) + ']: ' + IntToStr(my2DArray[a][b]));
      end;
    end.

  5. #5
    Join Date
    Jan 2012
    Posts
    64
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Okay thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •