Board index » delphi » Creating buttons during runtime

Creating buttons during runtime

Is creating buttons during run time possible? Basically what I am
trying to do is create an array of button objects on a form.  The
number of buttons will depend upon what type of error, message, note,
etc. we are going to display to the user.  The dialog in question is
actually a component which is first being created, once created, I am
attempting to create the buttons to display on the dialog box.

However, nothing I seem to do makes those &*@$*# buttons to appear.
Any help would be appreciated.  Below is some sample code.

private
        //... bunch of stuff above here
    TButtons : Array[1..5] of TButton;

//etc
//etc...

    FrmDialogComponent                := TfrmMZDialog.Create(self);
    TButtons[1] := TButton.Create(FrmDialogComponent);
     with TButtons[1] do begin
          Left     := 312;
          Top      := 34;
          Caption  := '&Next';
          TabOrder := 1;
          Visible  := TRUE;
          end; // with ... do begin

========================
Mich...@SOTA.COM
State Of The Art, Inc.
Financial Software
Creators of Acuity Financials,
            BusinessWorks, and
            MAS 90

800-447-5700
========================

 

Re:Creating buttons during runtime


You need to set the parent property of the button to something... probably
the form you're creating them in (see below).  This is different from the
Owner property, which is sent as the parameter to Create.  The help files
provide more information on this.

Quote
Mich...@SOTA.com (Mike Johnson) wrote:
>Is creating buttons during run time possible?

Yes. :)

Quote
>However, nothing I seem to do makes those &*@$*# buttons to appear.
>Any help would be appreciated.  Below is some sample code.

[snip]
Quote
>    FrmDialogComponent                := TfrmMZDialog.Create(self);
>    TButtons[1] := TButton.Create(FrmDialogComponent);

     TButtons[1].Parent := FrmDialogComponent;   // It should work now
Quote
>     with TButtons[1] do begin
>          Left     := 312;
>          Top      := 34;
>          Caption  := '&Next';
>          TabOrder := 1;
>          Visible  := TRUE;
>          end; // with ... do begin

Re:Creating buttons during runtime


Quote
Mike Johnson (Mich...@SOTA.com) wrote:

: Is creating buttons during run time possible? Basically what I am
: trying to do is create an array of button objects on a form.  The
: number of buttons will depend upon what type of error, message, note,
: etc. we are going to display to the user.  The dialog in question is
: actually a component which is first being created, once created, I am
: attempting to create the buttons to display on the dialog box.

: However, nothing I seem to do makes those &*@$*# buttons to appear.
: Any help would be appreciated.  Below is some sample code.

: private
:       //... bunch of stuff above here
:     TButtons : Array[1..5] of TButton;

: //etc
: //etc...

:     FrmDialogComponent                := TfrmMZDialog.Create(self);
:     TButtons[1] := TButton.Create(FrmDialogComponent);
:      with TButtons[1] do begin

<<<<<       parent   := FrmDialogComponent;    >>>>>>>>>>>>>>

:           Left     := 312;
:           Top      := 34;
:           Caption  := '&Next';
:           TabOrder := 1;
:           Visible  := TRUE;
:           end; // with ... do begin

Mike,

Add the line higlighted above. If the parent is not set the control will
not be visible, even if visible is set true.

good luck,

--
Ray Hildreth  
Greater Columbus Free-Net
rh...@freenet.columbus.oh.us

Re:Creating buttons during runtime


Check your code below again!

Quote
> However, nothing I seem to do makes those &*@$*# buttons to appear.
> Any help would be appreciated.  Below is some sample code.

> private
>    //... bunch of stuff above here
>     TButtons : Array[1..5] of TButton;

> //etc
> //etc...

>     FrmDialogComponent                := TfrmMZDialog.Create(self);
>     TButtons[1] := TButton.Create(FrmDialogComponent);
>      with TButtons[1] do begin
>           Left     := 312;
>           Top      := 34;
>           Caption  := '&Next';
>           TabOrder := 1;
>           Visible  := TRUE;

          Parent := FrmDialogComponent;

- Show quoted text -

Quote
>           end; // with ... do begin

> ========================
> Mich...@SOTA.COM
> State Of The Art, Inc.
> Financial Software
> Creators of Acuity Financials,
>             BusinessWorks, and
>             MAS 90

> 800-447-5700
> ========================

Other Threads