Merge tabs from child form to main form

I have page control in main forms and page elements in child form, I will place child form in main form using docking functions.

I am not using MDI style

Now both forms have tabs in the page control and I need to merge the child form of the tab into the main form control of the page, what is the best way to do this?

+2


source to share


3 answers


This is a fairly straightforward approach and may or may not suit your needs.

For each child tab, you need to combine:

  • Create a tab on the main page of the control form corresponding to the child Tab

  • Iterate over the controls in the child tab and change the Parent of the tab you just created



You don't need to deal with controls that are children of other controls. for example, if you have a group package in your child tab, then changing it will cause it and all the controls inside it to be added to the new parent.

If you need to "unwind" your tabs at any time, you will need to develop some kind of mechanism to keep track of where the controls were from so that you can restore the original Parent as / when needed.

To make things a little easier, you can place the TPanel on the child tabs and the Align property is alClient . Put all the controls in a tab on that panel, and then when you need to merge / unload, you only need to set the Parent of the panel control.

+2


source


The simplest and best way to handle multiple tabs in a page control is usually through frames. Take the contents of each tab and split them into a separate frame for each tab. Move any shared components, state, and code to the data module. Then just place those frames on the tabs of your page control.



+4


source


I just tried

procedure TForm1.Button1Click(Sender: TObject);
begin
  while Form2.PageControl1.PageCount > 0 do
    Form2.PageControl1.Pages[0].PageControl := PageControl1;
end;

      

and it worked fine. Am I missing something obvious or why is everyone suggesting such complex solutions? :-)

0


source