1

I have a two dimensional array. In a for loop, I want to do like this

procedure TForm1.Button2Click(Sender: TObject);
var i : integer;
    arr : array[0..2, 0..1] of integer;
    tmpArr : array[0..1] of integer;
begin
  arr[0, 0] := 0;
  arr[0, 1] := 92;

  arr[1, 0] := 1;
  arr[1, 1] := 75;

  arr[2, 0] := 2;
  arr[2, 1] := 70;

  for i := 0 to 2 do
    tmpArr := arr[i];

end;

But it says Incompatible types. I think arr[i] and tmpArr are both one dimensional array, each have two elements, aren't they?

1
  • What you really want here is a typed constant so you can get the data populated at compile time rather than runtime Commented Feb 5, 2018 at 10:56

1 Answer 1

6

Arrays that "look identical" are not assignment compatible in Delphi. You need to declare a type:

type
  TSomeArray = array[0..1] of integer;
var
  i: integer;
  arr: array[0..2] of TSomeArray;
  tmpArr: TSomeArray;
begin
  arr[0, 0] := 0;
  arr[0, 1] := 92;

  arr[1, 0] := 1;
  arr[1, 1] := 75;

  arr[2, 0] := 2;
  arr[2, 1] := 70;

  for i := 0 to 2 do
    tmpArr := arr[i];
end;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.