Ich versuche mich gerade an der dynamischen Erstellung einer GUI-Anwendung. Hierbei stellen sich mir zu Anfang zwei Fragen:
1. Geht das nur im MODE Delphi?
2. Das Button-Click-Event funktioniert mit dem remarkten Teil nicht. Was mache ich hier falsch?
Basis ist das Beisliel aus WIKI, damit spiele ich erts mal rum
Code: Alles auswählen
unit mainform;
{$MODE Delphi}{$H+}
interface
uses Forms, StdCtrls, Classes;
type
TMyForm = class(TForm)
public
MyButton: TButton;
MyEdit: TEdit;
procedure ButtonClick(ASender: TObject);
constructor Create(AOwner: TComponent); override;
end;
implementation
procedure TMyForm.ButtonClick(ASender: TObject);
begin
//Edit3.Text := Edit2.Text + ' ' + Edit1.Text;
end;
constructor TMyForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
//Hint: FormCreate() is called BEFORE Create() !
//so You can also put this code into FormCreate()
//(This is not the case when creating components ..)
Position := poScreenCenter;
Height := 400;
Width := 400;
VertScrollBar.Visible := False;
HorzScrollBar.Visible := False;
MyButton := TButton.Create(Self);
with MyButton do
begin
Height := 30;
Left := 100;
Top := 100;
Width := 100;
Caption := 'Close';
OnClick := ButtonClick;
Parent := Self;
end;
MyEdit := TEdit.Create(Self);
with MyEdit do
begin
Name := 'Edit1';
left := 120;
Top := 10;
Width := 250;
Parent := Self;
end;
MyEdit := TEdit.Create(Self);
with MyEdit do
begin
Name := 'Edit2';
left := 120;
Top := 40;
Width := 250;
Parent := Self;
end;
MyEdit := TEdit.Create(Self);
with MyEdit do
begin
Name := 'Edit3';
left := 120;
Top := 70;
Width := 250;
Parent := Self;
end;
// Erstellen Sie hier noch weitere Komponenten
end;
end.