views:

261

answers:

2

Best way to 'insert' a page in a TPageControl if i already have many pages full of controls? Let's say i want to insert a new page before TabSheet1.

Thanks.

UPDATE : At design time.

+3  A: 

You can try this

procedure TForm13.Button1Click(Sender: TObject);
Var
   tabSheet  : TTabSheet;
   AComponent: TComponent;
   aIndex    : Integer;
begin
   aIndex:=-1;
   AComponent := FindComponent('TabSheet1');
   if Assigned(AComponent) then
     if AComponent is TTabSheet then
     aIndex:=TTabSheet(AComponent).PageIndex;//get the index of the 'TabSheet1'  

   tabSheet:=TTabSheet.Create(PageControl1) ;
   tabSheet.PageControl:=PageControl1;
   tabSheet.Caption:='My TabSheet'+IntToStr(PageControl1.PageCount);
   if aIndex>-1 then
   tabSheet.PageIndex:=aIndex; //Set the index of the new TabSheet
end;

Update

In Designtime you must set the PageIndex Property to the PageIndex of the TabSheet1.

Bye.

RRUZ
There's a lot of code in that example. The part that actually *answers the question* is the last line, where `PageIndex` gets assigned a new value.
Rob Kennedy
I should have said inserting at design time. (May be i should edit my question?)
volvox
That's what i thought. OK - thank for the code anyway it will be usefull.
volvox
I'd vote this answer up if it wasn't a textbook example on how to (mis-)use indentation and white space to make code less readable.
mghie
So fix it, Mghie. It's a wiki.
Rob Kennedy
+6  A: 

Rightclick on the pagecontrol, and click New Page

After that, set the PageIndex property to place the new page where you want to have it.

Wouter van Nifterick