Entry
Delphi: Component: Dynamic: Create: How create dynamically a row of buttons, when clicking button?
Sep 19th, 2004 12:33
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 11 December 2003 - 11:55 pm -------------------
Delphi: Component: Dynamic: Create: How create dynamically a row of
buttons, when clicking button?
You can use the 'Create' method of the 'TButton' class, with itself as
a parameter, to create a new button
(this is similar to using the 'new' method in other computer
languages).
---
Steps: Overview:
1. -Start a new Delphi application
2. -Put a button on the form
3. -Double click on the button
4. -Replace the source code text with
the following text:
--- cut here ---------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
buttony : integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
buttony := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
var Btn : TButton;
begin
Btn := TButton.Create( Self );
Btn.Top := buttony;
buttony := buttony + Btn.Height;
Btn.Parent := Self;
end;
end.
--- cut here ---------------------------------------------------------
5. If you run this program, it will generate a new button
each time you click on this button
+-------------------+
| |
+-------------------+
+-------------------+
| |
+-------------------+
+-------------------+
| |
+-------------------+
...
+-------------------+
| |
+-------------------+
---
---
Internet: see also:
---
Delphi: Component: Dynamic: Create: How to create dynamically a button
component (e.g. when clicking on another component)?
http://www.faqts.com/knowledge_base/view.phtml/aid/24287/fid/175
----------------------------------------------------------------------