DELPHI - Merge / Migrate / Clone a child Form that inherits components from another form to create a 3rd independent form

In Delphi I'm looking for a way to clone a two forms (one that has an ancestor that inherits components and settings accordingly) into a new single form that has no ancestor requirement.

To try and describe this - let's say that I have two forms:

FORMANCESTOR contains 3 buttons on it sitting on a Panel. The captions on these buttons are set in FormAncestor, and Buttons are called BTN1, BTN2 and BTN3.

FORMCHILD is a descendant of FormAncestor so the panel with the 3 buttons inherits automatically and shows on FORMCHILD.  But FORMCHILD has BTN3's caption altered, and has a new 4th Button added to FORMCHILD.

What I would like to do is create a new form called FORMINDEPENDENT which has the 4 buttons and Panel, and inherits from TForm as opposed to TFormAncestor

I was just wondering if there is a standard way / correct method to merge / migrate / clone from decedents as per the above so that I have a new independent form that doesn't need to reference any ancestors and can just be a descendent directly from a TForm?


Adam HairAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
what you are describing is VFI, Visual Form Inheritance

no, that doesn't work
only would work if you subclass in code

but this idea of independance is wrong
a TForm ... any TForm class will always be dependant as they inherit from something like a TWinControl or other low level class
if you want your TForm to be independant, (except from TObject), then you'll have to define every method/property defined in ancestor classes

the idea of object oriented programming is to be able to inherit things
that implicitely makes a dependance
you can't inherit without being dependant

one very important thing :
if you want to create new properties and make them accessible via the property editor,
then you need to write code for those first, before adding components

you can add your custom forms to the component palette ... that's probably what you are looking for

here is an excellent example
Adam HairAuthor Commented:
Thanks @ Geert G.

I think you may have misunderstood my question (and I've probably phrased it poorly too)...

I was wanting to 'merge' the forms together, so formchild referred to TForm instead of TFormAncestor but keep all the objects/components and properties.

I think I've since found a workaround to what I'm chasing by doing the following:

1) Open up TFormChild

2) Select All components/Objects on the form and copy these...

3) Create a new from decending from TForm only

4) Paste the components onto the newly created form.

... this appears to work, ending up giving me all the components that were on TFormChild (including those that were inherited from TFormAncestor) but without having to refer to TFormAncestor.

The problem with this method is that any underlying code / (events and methods) that were on both TFormAncestor and TFormChild will have to be manually located and placed back into the newly created unit - but it does save me from having to recreate the whole unit from scratch again as all the components and properties come across.

I wasn't sure if there is a more elegant / correct way to perform this - but the copy/paste seems to have gotten me out of trouble.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert GOracle dbaCommented:
nope, nothing elegant exists
it's all copy/paste work

might be an idea for
but i doubt a lot of people would use that

you might be able to create a IDE Editor Wizard to do that, but it will require a lot of work

copy/paste will be way faster
Adam HairAuthor Commented:
It appears the best option to remove the requirement to refer to a ancestral form is to:

1) Open up the decendent / child form.

2) Select All components/Objects on the form and copy these to the clipboard.

3) Create a new from descending from TForm class only

4) Paste the components onto the newly created form.

Additional work will be required to link events on components and bring source code across.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.