uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Contnrs;
//Unit hinzugefügt für die Liste
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
lines,rows:integer;
//Die Variablen gehören zur Form (nicht global)
EditList:TComponentList;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
EditList:=TComponentList.create;
EditList.OwnsObjects:=true;
//wird dadurch Komponenten und Inhalt zusammen löschen
Width:=368;
//nicht auf die Form1-Variable zugreifen
Height:=95;
//kann man auch im OI einstellen
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
EditList.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var Edit:TEdit;
i,j:integer;
begin
if (trystrtoint(edit1.Text,rows))
and(trystrtoint(edit2.Text,lines))
and
(rows>0)
and(lines>0)
then
begin
if rows>10
then rows:=10;
if lines>10
then lines:=10;
Editlist.Clear;
//Liste und alle Edits löschen
if rows>4
then Width:=25+(rows+1)*(57+8);
Height:=110+lines*(21+8)-8;
for i:=1
to lines
do
begin
for j:=1
to rows
do
begin
Edit:=TEdit.Create(self);
EditList.Add(Edit);
with Edit
do
begin
Parent:=self;
Left:=16+(j-1)*64;
Top:=72+(i-1)*24;
width:=57;
Name:='
e'+inttostr(j)+inttostr(i);
//caption:='';
end;
end;
Edit:=TEdit.Create(self);
EditList.Add(Edit);
with Edit
do
begin
Parent:=self;
Left:=16+(rows-1)*64;
Top:=72+(i-1)*24;
width:=57;
Name:='
l'+inttostr(i);
//caption:='';
end;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
EditList.Clear;
end;