Hello,
Imagine a very complex form with a main control in it, a PageControl with several tabs. See the attached image please.
With toolbars, icons, buttons, comboboxes, charts, notebooks with multiple pages with different contents that expand or contract depending on the dimensions of the main window, a complex stringgrid inside, vertical and horizontal slicebars.... a real complex form, too hard for cloning it's components by hand, the way I allready know how to do it. I am sure there is another handy way to create a new instance of all this elements in a new tab.
The way I do it right now is:
1. when a user clicks the "create new Point of Sale window" calls a procedure in main form to add a new tab
2. copy each control from the pos tab into the empty tab, something like this:
procedure TmainScreen.SpeedButton_newTabClick(Sender: TObject);
var
k: integer;
newtab: TTabSheet;
newlabel: TLabel;
aPic : TPicture;
// start duplicating all the components in the POS tabsheet
// toolbar in the POS tabsheet
newBevel_toolbar: TBevel;
newSpeedButton_toolbarFirst: TSpeedButton;
newSpeedButton_toolbarPrevious: TSpeedButton;
begin
k := PageControl.PageCount + 1;
// we stablish the limit of 15 POS sessions opened at a time
if k <= 15 then begin
newtab := TTabSheet.Create(PageControl);
newtab.PageControl := PageControl;
newtab.name := 'tab'+inttostr(k);
newtab.Caption := 'TPV '+inttostr(k);
//---------------------------------------
//newlabel := TLabel.Create(newtab);
//newlabel.name := 'tablabel'+inttostr(k);
//newlabel.caption := 'Test'+inttostr(k);
//newlabel.left := 20;
//newlabel.top := 20;
//newlabel.visible := true;
//newlabel.parent := newtab;
// nueva barra de herramientas
newBevel_toolbar:= TBevel.Create(newtab);
newBevel_toolbar.Left := 0;
newBevel_toolbar.Height := 30;
newBevel_toolbar.Top := 0;
newBevel_toolbar.Width := 1765;
newBevel_toolbar.Align := alTop;
newBevel_toolbar.Shape := bsBottomLine;
newBevel_toolbar.visible := true;
newBevel_toolbar.parent := newtab;
// botón 1
newSpeedButton_toolbarFirst := TSpeedButton.Create(newtab);
newSpeedButton_toolbarFirst.Left := 5;
newSpeedButton_toolbarFirst.Height := 22;
newSpeedButton_toolbarFirst.Top := 3;
newSpeedButton_toolbarFirst.Width := 23;
newSpeedButton_toolbarFirst.Flat := True;
aPic := TPicture.Create;
aPic.LoadFromFile('C:\Users\Raúl\Proyectos\img-general\toolbars\1.png');
newSpeedButton_toolbarFirst.Glyph.Assign(aPic.Bitmap);
newSpeedButton_toolbarFirst.Transparent := False;
//OnClick = SpeedButton_toolbarFirstClick
newSpeedButton_toolbarFirst.ShowCaption := False;
newSpeedButton_toolbarFirst.visible := true;
newSpeedButton_toolbarFirst.parent := newtab;
(...)
Ok, all this for just ONE single button from the toolbar. ONE. Please, tell me there's an easier way to solve this problem because I'm not in the mood to clone the whole thing manually. I've read severall posts on the net but I have a lot of confusion. Some posts are from Delphi websites, other from Lazarus, etc.
TFrames is a way to handle this? RTTI? Can someone provide a simple example please? Maybe it's possible to save the contents of the POS tabsheet into a file and read it into the new tab?
Any idea is welcomed...
Thanks