I have a TPageControl
with a TTabSheet
. and in that TTabSheet
i have a bunch of functions and components. I would like to duplicate that tabSheet at run time via a button with all the functions and components still in it and working.
Right now I managed to duplicate the tabsheet. However, the new tabsheet is completely empty.
Here is my code for that button.
TTabSheet * NewTabSheet= new TTabSheet(pageControlMain);
NewTabSheet->PageControl = pageControlMain;
NewTabSheet->Caption = "TabSheet";
pageControlMain->ActivePage = NewTabSheet;
What am I missing?
As for the components and functions inside the TTabSheets, they're just scrollboxes, edits, buttons, and panels.
The
TTabSheet
class by itself does not have any child controls, that is why you don't see anything. You have to instantiate each individual control and copy their data as well.One way to do that is to use the
TStream.WriteComponent()
andTStream.ReadComponent()
methods to save the sourceTTabSheet
into a temporary DFM and then load that into the newTTabSheet
, eg:Another option is to place your components onto a
TFrame
-derived class at design-time, then create an instance of that class at run-time and place it onto eachTTabSheet
, letting it handle the controls for you, eg: