[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

2-dimensional open arrays ?

Posted on 1999-12-16
5
Medium Priority
?
205 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:val84
  • 2
  • 2
5 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 2289236
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
 

Accepted Solution

by:
Alphomega earned 400 total points
ID: 2289245
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
 

Author Comment

by:val84
ID: 2289401
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
 

Expert Comment

by:Alphomega
ID: 2290685
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
 

Author Comment

by:val84
ID: 2294201
Thanks Alphomega.
Regards, Alex.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question