unit Array1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

const
  xMax = 5;
  yMax = 4;
  zMax = 3;

var
  Form1: TForm1;
  Feld1D: Array[1..xMax] of Integer;
  Feld2D: Array[1..xMax,1..yMax] of Integer;
  Feld3D: Array[1..xMax,1..yMax,1..zMax] of Integer;
  Nr: Integer;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var i,j,k: Integer;
begin
  // Rahmen und Überschriften
  Canvas.Rectangle (20,20,180,70);
  Canvas.Rectangle (20,105,180,215);
  Canvas.Rectangle (ClientWidth div 2+15,20,ClientWidth div 2+175,320);
  Canvas.TextOut (40,10,'Feld1D');
  Canvas.TextOut (40,95,'Feld2D');
  Canvas.TextOut (ClientWidth div 2+25,10,'Feld3D');
  // weiter zählen
  inc (Nr); if Nr > 3 then Nr := 1;
  case Nr of
    1:
    // 1D-Feld belegen und anzeigen
    for i := 1 to xMax do
    begin
      Feld1D[i] := i;
      Canvas.TextOut (i*30,40,IntToStr(Feld1D[i]));
    end;
    2:
    // 2D-Feld belegen und anzeigen
    for i := 1 to xMax do
      for j := 1 to yMax do
      begin
        Feld2D[i][j] := i*j;
        Canvas.TextOut (i*30,j*20+104,IntToStr(Feld2D[i,j]));
      end;
    3:
    // 3D-Feld belegen und anzeigen
    for i := 1 to xMax do
      for j := 1 to yMax do
        for k := 1 to zMax do
        begin
          Feld3D[i][j][k] := i*j*k;
          Canvas.TextOut
            (i*30+ClientWidth div 2-5,j*20+k*95-75,IntToStr(Feld3D[i,j,k]));
        end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Color := clWhite;
  Nr := 0;
end;

end.
