Board index » delphi » Delphi2: TPageControl, TTabSheet runtime creation problems

Delphi2: TPageControl, TTabSheet runtime creation problems

Hi,

I'm having trouble creating a TTabSheet in a TPageControl at runtime.

On my form I have:
Tabs : TPageControl;
Page1: TTabSheet;

At runtime I want to add Page2.
This is what I do:
{Page2 is a global defined TTabSheet}

procedure TMainForm.NewPageClick(Sender: TObject);
begin
  Page2 := TTabSheet.Create(Tabs);
  Page2.Parent := Tabs;
  Page2.Enables := True;
  Page2.Visible := True;
  Page2.TabVisible := True;
end;

This doesn't work, can somebody give me a hint?

Thanx, Dik

 

Re:Delphi2: TPageControl, TTabSheet runtime creation problems


I use this to create a new tab:

-----
procedure TMainForm.MakeNewTab;
var
        newTab: TTabSheet;
begin
        {Create the tab sheet and set some properties}
        newTab := TTabSheet.Create(Self);
        newTab.Caption := '(empty)';

        {Add it to the main pageControl}
        newTab.PageControl := MyPageControl;

        {Make it the active page}
        PageControl.ActivePage := newTab;
end;
-----

Two things you're missing. When you CREATE it, the parameter
is for the OWNER of the component you're creating, not
the parent. The owner is the form. The other thing that actually
adds it is by setting its PageControl property.

Hope this helps!

Ron Manske

Quote
> dikb...@worldaccess.nl (Dik Bots) wrote in article

<N.061896.192840...@ehv2-5.worldaccess.nl>...
Quote
> Hi,

> I'm having trouble creating a TTabSheet in a TPageControl at runtime.

> On my form I have:
> Tabs : TPageControl;
> Page1: TTabSheet;

> At runtime I want to add Page2.
> This is what I do:
> {Page2 is a global defined TTabSheet}

> procedure TMainForm.NewPageClick(Sender: TObject);
> begin
>   Page2 := TTabSheet.Create(Tabs);
>   Page2.Parent := Tabs;
>   Page2.Enables := True;
>   Page2.Visible := True;
>   Page2.TabVisible := True;
> end;

> This doesn't work, can somebody give me a hint?

> Thanx, Dik

Re:Delphi2: TPageControl, TTabSheet runtime creation problems


Quote
Dik Bots wrote:
> I'm having trouble creating a TTabSheet in a TPageControl at runtime.
> [...]
> At runtime I want to add Page2.
> This is what I do:

> procedure TMainForm.NewPageClick(Sender: TObject);
> begin
>   Page2 := TTabSheet.Create(Tabs);
>   Page2.Parent := Tabs;
>   Page2.Enables := True;
>   Page2.Visible := True;
>   Page2.TabVisible := True;
> end;

Try this:

var
   sheet : TTabSheet;
begin
   sheet := TTabSheet.Create(self);
   sheet.pagecontrol := pageControl1;
end;

Hope this helps
  Guido

--
Guido Schoepp
eMail: 101644.2...@compuserve.com  Bonner GeneralAnzeiger
Voice: +49 (228) 6688-187          Justus-von-Liebig-Strasse
  Fax: +49 (228) 6688-170          D-53121 Bonn

Re:Delphi2: TPageControl, TTabSheet runtime creation problems


Quote
Dik Bots wrote:
> I'm having trouble creating a TTabSheet in a TPageControl at runtime.
> [...]
> At runtime I want to add Page2.
> This is what I do:

> procedure TMainForm.NewPageClick(Sender: TObject);
> begin
>   Page2 := TTabSheet.Create(Tabs);
>   Page2.Parent := Tabs;
>   Page2.Enables := True;
>   Page2.Visible := True;
>   Page2.TabVisible := True;
> end;

Try this:

procedure TMainForm.NewPageClick(Sender: TObject);
begin
   page2 := TTabSheet.Create(self);
   page2.pagecontrol := Tabs;
end;

Hope this helps
  Guido

--
Guido Schoepp
eMail: 101644.2...@compuserve.com  Bonner GeneralAnzeiger
Voice: +49 (228) 6688-187          Justus-von-Liebig-Strasse
  Fax: +49 (228) 6688-170          D-53121 Bonn

Other Threads