I need to clone a TAdvGroupBox with entire children and at best even with the registered event handlers, such that a new TAdvGroupBox constains the same controls liek the source one, at the exact same positions and such. Afterwards I would like to add the cloned instance to a TScrollBox.
I already tried the Assign method, but only got an exception that TAdvGroupBox can't be assigned to TAdvGroupBox. Afterwards I tried to iterate the child controls of the source group box to clone those. same error, just with the TComboBox I tried first.
Is there any easy way to clone such a TAdvGroupBox including all childs? Or do I really need to create all of those manually with all their positions and settings and whatever...?
Thanks!
Maybe you can use the clipboard?
var
grp: TAdvGroupBox;
begin
RegisterClass(TAdvGroupBox);
clipboard.SetComponent(advgroupbox1);
grp := clipboard.GetComponent(self, self) as TAdvGroupBox;
grp.Left := 0;
grp.Top := 0;
end;
Thanks for the idea, that works, but one has to copy the children manually. At least their position and data within the group is preserved, so looks like one can save some manual layout. If anyone is interested, the following is my PoC:
#include <Clipbrd.hpp>
RegisterClasses(&__classid(TAdvGroupBox), 0);
RegisterClasses(&__classid(TComboBox), 0);
RegisterClasses(&__classid(TEdit), 0);
RegisterClasses(&__classid(TButton), 0);
TClipboard* clipBoard = Clipboard();
clipBoard->SetComponent(groupBox);
TAdvGroupBox* clonedGroupBox = dynamic_cast<TAdvGroupBox*>(clipBoard->GetComponent(scrollBox, scrollBox));
clonedGroupBox->Caption = L"Clipboarded";
clonedGroupBox->Top = groupBox->Top + groupBox->Height + 5;
for (int i = 0; i < groupBox->ControlCount; ++i)
{
TControl* tmplChild = groupBox->Controls;
clipBoard->SetComponent(tmplChild);
clipBoard->GetComponent(clonedGroupBox, clonedGroupBox);
}