Board index » delphi » PageControl - Adding control populated pages at runtime

PageControl - Adding control populated pages at runtime

I need to create pages of a PageControl on the fly in 3 set formats --
there can be any number (or none) of each format. The layout of the
formats is a combination of DBControls: edits, checkboxes, etc.

Creating the pages is not a problem, using the following:

        procedure Tform.btnAddPageClick(Sender: TObject);
        with TTabSheet.Create(Self) do begin
                Caption := 'sometext';
        {Assign PageControl1 to the TTabSheet's PageControl property}
                PageControl := PageControl1;
                PageControl1.ActivePage := PageControl1.Pages[PageIndex];
        end;
        end;

But, the only way I've found to populate the page is, for example with
a button, by doing the following:

        Button1 := TButton.Create(Self);
        Button1.Parent := PageControl1.ActivePage;
        Button1.Top := 10;
        Button1.Left := 10;
        Button1.Width := 113;
        Button1.Caption := 'sometext';
        Button1.OnClick := someprocedure;
        etc...

Since I need to place about 30 controls on each page format, this
seems like a messy way to set all the properties and events. Is there
a way to visually design the 3 page formats, then create an object to
assign to the pagecontrol page?

I'm stumped...

Jeff Hamblin
San Diego,CA

 

Re:PageControl - Adding control populated pages at runtime


On Thu, 06 Mar 1997 04:11:23 GMT, jhamb...@n2.net (Jeff Hamblin)
wrote:

Quote
>I need to create pages of a PageControl on the fly in 3 set formats --
>there can be any number (or none) of each format. The layout of the
>formats is a combination of DBControls: edits, checkboxes, etc.
[...]
>But, the only way I've found to populate the page is, for example with
>a button, by doing the following:

>    Button1 := TButton.Create(Self);
>    Button1.Parent := PageControl1.ActivePage;
>    Button1.Top := 10;

[...]

Quote
>Since I need to place about 30 controls on each page format, this
>seems like a messy way to set all the properties and events. Is there
>a way to visually design the 3 page formats, then create an object to
>assign to the pagecontrol page?

I've been working on a PageControl dominated app lately and resorted
to using Forms as TTabSheet childwindows.

a) design your 3 forms (if they are very similar you can design a
BaseForm first and derive from it). I found out that it is essential
that those windows have BorderStyle set no bsNone.

b) remove them from the auto-create list in Project|Options

c) After creating the TabSheet, create an instance of the Form and use
the TabSheet as  Owner and Parent . Say  Form.Show; and there it is.

Set  Form.Align := alClient and/or Form.WindowStyle := wsMaximized

Note : If the SheetForms need to access elements of the MainForm a lot
this can become a bit messy.  I came across an item in the CWG help
file about designing a form, manipulating the DFM as text and
converting the Form to a Panel-component. I have not tried that.

good luck,
-hh-

PS: mail me if you need code snippets, the above is from memory.

Other Threads