procedurepascal

# How to represent an array as a procedure

``````uses GraphABC;
var
x, y: integer;

procedure kv(x, y: integer; color: system.Drawing.Color);
begin
Rectangle(x, y, x + 20, y - 50);
FloodFill(x + 10, y - 10, color);
end;

procedure DrawPyramid(arr: array of array [1..2] of integer);
begin
for var i := 1 to Length(arr) do
begin
kv(arr[i], arr[i], clRed);
end;
end;

var arr: array of array [1..2] of integer;

begin
SetPenColor(clBlack);
kv(40, 50, clGreen);
x := 80;
y := 100;
SetLength(arr, 4);

for var i := 1 to 3 do
begin
arr[i] := x - 20 * i;
arr[i] := y;
end;

x := 120;
y := 150;
SetLength(arr, 9);

for var i := 4 to 8 do
begin
arr[i] := x - 20 * (i-3);
arr[i] := y;
end;

for var i := 1 to 3 do
begin
kv(arr[i], arr[i], clOrange);
end;

for var i := 1 to 5 do
begin
arr[i] := x - 20 * (i+1);
arr[i] := y;
kv(arr[i], arr[i], clRed);
end;

end.
``````

I don't understand how to correctly insert an array representing a pyramid into a procedure (not a "kv" procedure) with which I will perform operations in the future, for example, to copy a pyramid.

I looked at several options from the Internet, but still did not understand how to technically represent an array in my code in the procedure.

Solution

• I think this is what you're looking for (although your question is somewhat unclear).

``````uses GraphABC;
type
TTwoDimArray = array of array[1..2] of integer;
var
x, y: integer;

procedure kv(x, y: integer; color: system.Drawing.Color);
begin
Rectangle(x, y, x + 20, y - 50);
FloodFill(x + 10, y - 10, color);
end;

procedure DrawPyramid(arr: TTwoDimArray);
begin
for var i := 1 to Length(arr) do
begin
kv(arr[i], arr[i], clRed);
end;
end;

var
arr: TTwoDimArray;

begin
SetPenColor(clBlack);
kv(40, 50, clGreen);
x := 80;
y := 100;
SetLength(arr, 4);

for var i := 1 to 3 do
begin
arr[i] := x - 20 * i;
arr[i] := y;
end;

x := 120;
y := 150;
SetLength(arr, 9);

for var i := 4 to 8 do
begin
arr[i] := x - 20 * (i-3);
arr[i] := y;
end;

for var i := 1 to 3 do
begin
kv(arr[i], arr[i], clOrange);
end;

for var i := 1 to 5 do
begin
arr[i] := x - 20 * (i+1);
arr[i] := y;
kv(arr[i], arr[i], clRed);
end;

end.
``````