combining objects from 2 forms into one

hey all
how can I say this, is it possible to insert objects from one form into another form without having to create them?
my main form is minimal and I like it that way, I dont want an app that can take up the whole screen (sort of like icq etc...)
and I open a second form in that app whenever I want to see xtra info which is not often.

Now I know some people who might use this app will probably not like my design. and might want all forms combined into a single form...
so is it possible to combine/insert 2 forms into one? or be able to move the objects from one form into the other at run time?
 or will I have to have 2 different interfaces and switch between them?

Who is Participating?
BlackTigerXConnect With a Mentor Commented:
you can have panels in your form, and sure, you can switch controls from one panel to another,

I put two panels, put a label in one of them, then added this code in some button click event:


the label gets put into Panel2 no problems

You could put the objects onto panels and show and hide the panels, or use tab and show and hide the tabs.

You can also get controls that embed the Forms (I think ABC do one - its on the Delphi 7 CDs).

Eddie ShipmanAll-around developerCommented:
Use Frames. See the topic "Working with frames" in the help file.

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Eddie ShipmanConnect With a Mentor All-around developerCommented:
"A frame (TFrame), like a form, is a container for other components. It uses the same ownership mechanism as forms for
automatic instantiation and destruction of the components on it, and the same parent-child relationships for synchronization
of component properties.

In some ways, however, a frame is more like a customized component than a form. Frames can be saved on the
component palette for easy reuse, and they can be nested within forms, other frames, or other container objects. After a
frame is created and saved, it continues to function as a unit and to inherit changes from the components (including other
frames) it contains. When a frame is embedded in another frame or form, it continues to inherit changes made to the frame
from which it derives.

Frames are useful to organize groups of controls that are used in multiple places in your application. For example, if you
have a bitmap that is used on multiple forms, you can put it in a frame and only one copy of that bitmap is included in the
resources of your application. You could also describe a set of edit fields that are intended to edit a table with a frame and
use that whenever you want to enter data into the table."
esoftbgConnect With a Mentor Commented:
You may move objects from one form into another form at Runtime:
  Form2.Edit1.Parent := Form1.Panel1;
This way Edit1 from Form1 will be moved on Form1.Panel1;
It is easy as you see .... More difficult is if you want to save the configuration and at next start of the application to appear with the new design. For this purpose you may use the Windows registry or .ini file, or Database ....
> This way Edit1 from Form1 will be moved on Form1.Panel1;
to be readed as
This way Edit1 from Form2 will be moved on Form1.Panel1;
What is construction Form2.Edit1 ?
  1.)  Form2 is the Owner of Edit1;
  2.)  Edit1 is the Object (the component);
  3.)  B := (Edit1.Owner=Form1); will be equal to B := True;
  4.)  Owner is a ReadOnly prperty (it could not be changed at all);
  5.)  Parent property can be changed and:
      5.1.) Form2.Edit1.Parent := Form1.Panel1; //  Edit1 with owner Form2 appears on Form1.Panel1;
      5.2.) Form2.Edit1.Parent := Form2.Panel1; //  Edit1 with owner Form2 appears on Form2.Panel1;
agreed with Eddie ... go with frames
design it like a normal form, then your end form hosts those frames that the user likes
kretzschmarConnect With a Mentor Commented:
>so is it possible to combine/insert 2 forms into one?

i dislike frames, even if this may a solution for you,
but you can also embed two forms into a third one like

have on the third for two panels or a tpagecontrol with two ttabsheets.
in the formcreate of this thirdform use something like this

  with tform1.create(self) do
    parent := panel1;
    borderstyle := bsNone;
    align := alClient;
  with tform2.create(self) do
    parent := panel2;
    borderstyle := bsNone;
    align := alClient;

just remove tform1/tform2 from the autocraete
in the project-options and make tform3 to your mainform.

meikl ;-)
and I dislike "hacks" like these :)
its not a hack, its a possibility,
which worked satisfactorily in practice

meikl ;-)
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
In my opinion in this case should be better to use docked forms.
For example a user that likes the ICQ style will continue to use it so, but if some user want to see the whole forms, or just some important (for him) one, he could decide to dock it to the Main one, something like Winamp do...

This could be a good solution without make too many changes at application and form level, and will let the user to decide wich is his better view style.....
Eddie ShipmanAll-around developerCommented:
Hey, kretzschmar, why the disdain for frames?

Have you had any experience with them? They are wonderful for portions of forms that are being
reused and extended. For someone with your experience, I am surprised to see you say that.
>Hey, kretzschmar, why the disdain for frames?
>Have you had any experience with them?

yep, i have experience. the concept of tframes is genius but the ide
implemention is a pain. as long as you develop a tframe until finish
and embed it then all works fine, but if you have already embedded
the tframe, and you have to change somewhat on the tframe itself,
the embedded tframes may not notice this change under some conditions,
specially if you have done adjustments on the embedded tframe.
my workaround of this bahaviour was to delete the embedded frame
and insert it new.

also is there an align/anchor problem, which caused me to not align
embeded tframes at designtime, and do the alignment at runtime

about this see (actual)

also i missed there the onCreate/onDestroy-events

meikl ;-)
Eddie ShipmanAll-around developerCommented:
While your arguments have validity, the majority of developers that use them are enamored.
I would think that what the OP is asking could be handled very easily with frames and what
others have posted is actually overkill.

While the alignment problems have not been remedied in later versions of Delphi, we were
able to add the OnCreate and OnDestroy events for Frames at my previous employer.
My current job doesn't require the use of frames and I have since forgotten how it was done.

LMuadDIbAuthor Commented:
good info here, thanx all...
didnt think it could be that easy with using parent
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.