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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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; )
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(M Rows[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.
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(M
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.
ASKER
Thanks Alphomega.
Regards, Alex.
Regards, Alex.
type
T2DimDynamicArr = array of array of integer;
procedure Test(var twoDimArr: T2DimDynamicArr);
Regards, Madshi.