Solved

combining objects from 2 forms into one

Posted on 2004-09-07
17
381 Views
Last Modified: 2010-04-04
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?

curious...
0
Comment
Question by:LMuadDIb
  • 4
  • 4
  • 3
  • +5
17 Comments
 
LVL 13

Accepted Solution

by:
BlackTigerX earned 250 total points
ID: 12000345
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:

Label1.Parent:=Panel2

the label gets put into Panel2 no problems
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 12000348
Hi

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).

Voodooman
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12000525
Use Frames. See the topic "Working with frames" in the help file.

0
 
LVL 26

Assisted Solution

by:EddieShipman
EddieShipman earned 100 total points
ID: 12000534
"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."
0
 
LVL 12

Assisted Solution

by:esoftbg
esoftbg earned 50 total points
ID: 12001293
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 ....
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12001309
> 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;
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12003219
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;
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12003312
agreed with Eddie ... go with frames
design it like a normal form, then your end form hosts those frames that the user likes
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 100 total points
ID: 12003500
>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

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

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

meikl ;-)
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 12003525
and I dislike "hacks" like these :)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12003541
its not a hack, its a possibility,
which worked satisfactorily in practice

meikl ;-)
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12004832
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.....
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12006087
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.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12006335
>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)
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21122778.htmland
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10336365.html

also i missed there the onCreate/onDestroy-events

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12006356
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12007744
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.

0
 
LVL 4

Author Comment

by:LMuadDIb
ID: 12007795
good info here, thanx all...
didnt think it could be that easy with using parent
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now