Return number of rows or columns of an array

Asked

Viewed 453 times

0

I have a matrix like this in Delphi XE8: Matriz[2][3].

I wonder which method can I use to return the number of rows or columns in this matrix, my idea is to loop with 2 for's and traverse the matrix elements by inserting them into a table in the DataBase and then retrieve them in a report with the component TfrxDbDataset.

1 answer

1


For you to walk a Array Multi dimensional it is necessary to make two laços de repetição, follows an example:

var
  Matriz: Array[0..1][0..2] of String;
  i, i1: Integer;
begin
  //Laço de repetição para percorrer as linhas, i representará a linha
  for i := 0 To High(Matriz) do
    begin
      //Laço de repetição para representar as colunas, i1 representará a coluna
      for i1 := 0 To High(Matriz[i]) do
        begin
          Matriz[i][i1]; //Aqui estará o conteúdo de cada espaço do seu Array
        end;
    end;
end;
  • 1

    Sorry, I typed wrong, I’ll correct. Both work, but in Length would have to have a - 1 then not to give Access Violation. High returns the last position, while Length returns the size.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.