Link to home
Start Free TrialLog in
Avatar of val84
val84

asked on

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.
Avatar of Madshi
Madshi

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.
ASKER CERTIFIED SOLUTION
Avatar of Alphomega
Alphomega

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of val84

ASKER

Thanks Alphaomega & Madshi.
Question for Alphaomega: your solution implies that one range of indexes is fixed?
(you put  
  MCols=array[0..1] of integer;  )
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.
Avatar of val84

ASKER

Thanks Alphomega.
Regards, Alex.