Hi there,
Try something like the following:
na
program JagArrDemo;
type
TDynArray = Array of Integer;
TJaggedArray = Array of TDynArray;
var
JagArray: TJaggedArray;
i,j: integer;
procedure SizeJagArray(Size: Integer; var JArray: TJaggedArray);
begin
//set the initial size of a jagged array
SetLength(JArray,Size);
end; {SizeJagArray}
procedure SizeJagArrayElement(Indx, Size: Integer; var JArray: TJaggedArray);
begin
//set the size of an element in a jagged array
if (Indx>-1) and (Indx<=High(JArray)) then
SetLength(JArray[Indx],Size)
else
//display "index out of bounds" error
WriteLn('Index out of bounds "',Indx,'".');
end; {SizeJagArrayElement}
procedure initJagArray(var JArray: TJaggedArray);
var i,j: integer;
begin
//initialise a jagged array
for i:=Low(JArray) to High(JArray) do
for j:=Low(JArray[i]) to High(JArray[i]) do
JArray[i,j]:=0;
end; {initJagArray}
begin
//initialise
SizeJagArray(10,JagArray);
//set jagged ellement sizes
for i:=Low(JagArray) to High(JagArray) do
SizeJagArrayElement(i,i+1,JagArray);
//initialise jagged array
initJagArray(JagArray);
//populate array
for i:=Low(JagArray) to High(JagArray) do
for j:=Low(JagArray[i]) to High(JagArray[i]) do
JagArray[i,j]:=j;
//finally check array
for i:=Low(JagArray) to High(JagArray) do
begin
WriteLn('JagArray[',i,'] has ',High(JagArray[i])+1,' elements.');
for j:=Low(JagArray[i]) to High(JagArray[i]) do
WriteLn(' - JagArray[',i,',',j,']=',JagArray[i,j]);
end;
end.