<p>Is there a simple way to duplicate all child components under parent component, including their published properties?</p>

<p>For example:</p>

<ul>
<li>TPanel

<ul>
<li>TLabel</li>
<li>TEdit</li>
<li>TListView</li>
<li>TSpecialClassX</li>
</ul></li>
</ul>

<p>Of course the most important factor, it should duplicate any new component which I drop on the TPanel without modifying the code under normal circumstances.</p>

<p>I've heard of the RTTI, but never used it actually. Any ideas?</p>

It's actually fairly easy to duplicate existing components at runtime.  The difficult part is to copy all of their published properties to the new (duplicated) objects.
I'm sorry, but my code example is in C++Builder.  The VCL is the same, just a different language.  It shouldn't be too much trouble to translate it Delphi:
```
```
for (i = 0; i < ComponentCount; ++i) {
    TControl *Comp = dynamic_cast<TControl *>(Components[i]);
    if (Comp) {
        if (Comp->ClassNameIs("TLabel")) {
            TLabel *OldLabel = dynamic_cast<TDBEdit *>(Components[i]);
            TLabel *NewLabel = new TLabel(this);  // new label
            // copy properties from old to new
            NewLabel->Top = OldLabel->Top;
            NewLabel->Left = OldLabel->Left;
            NewLabel->Caption = Oldlabel->Caption
            // and so on...
        } else if (Comp->ClassNameIs("TPanel")) {
            // copy a TPanel object
        }
```
```
Maybe somebody has a better method of copying all of the published properties of the old control to the new one.