2-dimensional open arrays ?

Hi everybody.

Open arrays are useful for passing to a procedure, as parameters, arrays of different sizes. But this arrays must be one dimensional. It is possible to do the same for 2-dimensional arrays?

Regards, Alex.
val84Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MadshiCommented:
AFAIK, not in D1-3. But in D4 and D5 you can use dynamical arrays like this:

type
  T2DimDynamicArr = array of array of integer;

procedure Test(var twoDimArr: T2DimDynamicArr);

Regards, Madshi.
0
AlphomegaCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type

 MCols = array[0..1] of integer;

 TMyArray = array of MCols;

  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormClick(Sender: TObject);
  private
    procedure Test(MRows: TMyArray);
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Test(MRows: TMyArray);
var I: integer;
begin
 for I := 0 to high(MRows) do
  memo1.Lines.Add(IntToStr(MRows[I][0]) + ' / ' + IntToStr(MRows[I][1]));
end;

procedure TForm1.FormClick(Sender: TObject);
var
 F: TMyArray;
 Cl, Rw: integer;
begin
 SetLength(F, 3);
 For Rw := low(F) to high(F) do
  for Cl := 0 to 1 do
   F[Rw][Cl] := random(25);
 Test(F);
 F := nil;
end;

end.
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
val84Author Commented:
Thanks Alphaomega & Madshi.
Question for Alphaomega: your solution implies that one range of indexes is fixed?
(you put  
  MCols=array[0..1] of integer;  )
0
AlphomegaCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type

 TMyArray = array of array of integer;


  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormClick(Sender: TObject);
  private
    procedure Test(MRows: TMyArray);
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Test(MRows: TMyArray);
var
 I, J: integer;
 S: string;
begin
 with memo1.Lines do
  begin
   clear;
   Add('Col quantity = ' + IntToStr(high(MRows)));
   Add('Row Quantity = ' + IntToStr(high(MRows[1])));
   Add('');
  end;
 for I := 0 to high(MRows) do
  for J := 0 to high(MRows[0]) do
   memo1.Lines.Add(IntToStr(MRows[I, J]));
end;


procedure TForm1.FormClick(Sender: TObject);
var
 F: TMyArray;
 Cl, Rw: integer;
begin
 SetLength(F, 2, 3);
 F[0, 0] := 10; F[0, 1] := 20; F[0, 2] := 30;
 F[1, 0] := 40; F[1, 1] := 50; F[1, 2] := 60;
 Test(F);
 F := nil;
end;

end.
0
val84Author Commented:
Thanks Alphomega.
Regards, Alex.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.