Dynamic form components creation in Lazarus/de
From Lazarus wiki
Jump to navigationJump to search
unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TForm1 } TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure ButtonClick(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); var ed: TEdit; but: TButton; begin ed:=TEdit.Create(self); ed.Parent:=self; ed.top:=8; ed.Left:=10; ed.Width:=ClientWidth-2*ed.left; ed.text:='Bitte geben sie den Text ein'; but:=TButton.Create(self); but.parent:=self; but.top:=ed.Top+ed.Height; but.left:=ed.Left; but.Caption:='Klickmich'; but.OnClick:=@ButtonClick; end; procedure TForm1.ButtonClick(Sender: TObject); begin showmessage('Hallo Welt'); end; end.
--Sven 22:00, 20 June 2011 (CEST)