Jump to content
lilkittenz

question about storing arrays within 2D arrays

Recommended Posts

I'm still fairly new to programming concepts, especially arrays.

 

what I want to do is set an array of values within a 2D array equal to another array

 

This is an example of what I mean:

 

program New;

var
SomeArray: Array[0..9] of Integer;
Some2DArray: Array[0..9] of Array[0..9] of integer;

begin
Some2DArray[0]:= SomeArray;
end.

 

I am currently getting a type Mismatch, but if Some2DArray[0] holds an array than why can't I set it equal to another array?

Or am I misunderstanding how 2D arrays work?

Link to comment
Share on other sites

Thats because your treating you 2d array like a 1d array. Also you never specified which array you want to set. Heres a working example

 

[scar]

program New;

 

var

SomeArray: Array[0..9] of Integer;

Some2DArray: Array[0..9] of Array[0..9] of integer;

I: Integer;

 

begin

Some2DArray[0][0]:= SomeArray[0];

For I := 0 to High(SomeArray) do

Some2DArray[0] := SomeArray;

end.

 

[/scar]

Link to comment
Share on other sites

It judges your 2 declarations of the base array of Integer as different types, you need to declare the array as a type first, then it will work.

 

[scar]type

T10Ints = array[0..9] of Integer;

 

var

SomeArray: T10Ints;

Some2DArray: array[0..9] of T10Ints;

 

begin

Some2DArray[0]:= SomeArray;

end.[/scar]

Link to comment
Share on other sites

It judges your 2 declarations of the base array of Integer as different types, you need to declare the array as a type first, then it will work.

 

[scar]type

T10Ints = array[0..9] of Integer;

 

var

SomeArray: T10Ints;

Some2DArray: array[0..9] of T10Ints;

 

begin

Some2DArray[0]:= SomeArray;

end.[/scar]

 

Never tried it in a type before. Bookmarked! Thanks Freddy

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...