Board index » delphi » Creating labels/buttons at runtime

Creating labels/buttons at runtime

Is there a way to create a button, label etc on a form at runtime.
I want to be able to create a database based on some parameters and
questions and then generate the form. But i cannot work out how to do this
!!

any help would be great

thanks

 

Re:Creating labels/buttons at runtime


Create the button just like all other objects.  Pass it a parameter that
represents the owner of the button.  The owner, typically the form on which
it resides, will destroy the button when it is freed.  You then have to set
the parent of the button to whatever container you want the button to
reside in, and voila!  Of course, a button is useless without an event
handler, so you might want to set that as well, along with other button
properties.

Like this...

MyButton := TButton.Create(Self);
with MyButton do begin
  Parent := Self;  // or Panel1, or ScrollBox1, or TabSheet1...
  Left := 10;
  Top := 10;
  Caption := 'Delphi Rocks';
  OnClick := MyClickProcedure;
end;

I am sure this must be in some FAQs, but rather than cut you off, I think
it just as easy to answer!!!

GNP,
Ken
--------------------------------------
Notice at no time do my fingers leave my hands...
This Internet thing...  it's a fad!  ;-)
--------------------------------------
Master Certified Delphi 3 Instructor
Master Certified C++Builder Instructor
k...@knowledgeable.com
ka...@oakland.edu
+

Mark Russell <m...@russells.demon.co.uk> wrote in article
<01bc509d$bf979080$877b9...@markr.UNIDATA.COM>...

Quote
> Is there a way to create a button, label etc on a form at runtime.
> I want to be able to create a database based on some parameters and
> questions and then generate the form. But i cannot work out how to do
this
> !!

> any help would be great

> thanks

Re:Creating labels/buttons at runtime


Hello "Mark!

Thursday April 24 1997, "Mark Russell" wrote to All:

 MR> Is there a way to create a button, label etc on a form at runtime.
 MR> I want to be able to create a database based on some parameters and
 MR> questions and then generate the form. But i cannot work out how to do this
 MR> !!

Creating a button:

Procedure TForm1.ButtonClick(Sender : TObject);
Begin
  Showmessage('Clicked my {*word*82};-)');
End;

Procedure TForm1.CreateForm(Sender : TObject);
Var
  Button : TButton;
Begin
  With Button Do Begin
    TButton.Create(Form1);
    Left:=20;
    Top:=20
    Width:=100;
    Parent:=Form1;
    Button.OnClick:=ButtonClick;
  End;
End;

Kind regards Ole

    E-Mail: Ole_Morten...@Hotmail.com

Other Threads