Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How can I embed a form in another form?


This question is answered. Helpful answers available: 0. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Dec 10, 2015 12:32 PM Last Post By: Sean Farley
Sean Farley

Posts: 9
Registered: 8/10/09
How can I embed a form in another form?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 9, 2015 9:51 AM
I have a VCL project which uses OpenGL, and I am trying to redo it using FireMonkey. In the old project, I used a ScrollBox to display the OpenGL environment, but FireMonkey components don't have the Handle member I need, so I have to replace the ScrollBox with a form, or so I believe.

So I am trying to put a child form inside a parent form, hoping that it will behave like a client aligned component, resizing and moving when the parent form is resized or moved.

I think I have found examples of how to do this, but they are in Delphi, which I have no experience with. I've tried to emulate in C++ without success.

So, how can I embed a form? Or, is there a different approach to using OpenGL with FireMonkey that I should consider?

I'm using RAD Studio 10 Seattle.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How can I embed a form in another form?
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 9, 2015 10:36 AM   in response to: Sean Farley in response to: Sean Farley
Sean wrote:

I think I have found examples of how to do this, but they are in
Delphi, which I have no experience with. I've tried to emulate in
C++ without success.

Just about everything you can do in Delphi can be done in C++ as well. What
is the actual Delphi code you are having trouble converting to C++?

--
Remy Lebeau (TeamB)
Sean Farley

Posts: 9
Registered: 8/10/09
Re: How can I embed a form in another form?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2015 11:43 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Sean wrote:

I think I have found examples of how to do this, but they are in
Delphi, which I have no experience with. I've tried to emulate in
C++ without success.

Just about everything you can do in Delphi can be done in C++ as well. What
is the actual Delphi code you are having trouble converting to C++?

--
Remy Lebeau (TeamB)

Upon closer examination of the Delphi examples, I don't think they are actually accomplishing what I am looking for. For example:

begin
while AForm.ChildrenCount>0 do
AForm.Children[0].Parent:=AParent;
end;

This appears to just move components from one form to another. This example:

procedure THostForm.FormCreate(Sender: TObject);
begin
FForm := TChildForm.Create( Self );
FForm.Panel1.Parent := Self;
end;

seemed promising, but it's actually just moving the panel component from the child form to the parent form. I think.

I've tried setting childForm->Parent = parentForm, but this doesn't seem to have any effect.

I can set the childForm position and size when the parentForm is created or resized, but there doesn't seem to be an OnMove event, so when the parentForm is moved, the childForm is left behind.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How can I embed a form in another form?
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2015 12:06 PM   in response to: Sean Farley in response to: Sean Farley
Sean wrote:

Upon closer examination of the Delphi examples, I don't think they
are actually accomplishing what I am looking for. For example:

begin
while AForm.ChildrenCount>0 do
AForm.Children[0].Parent:=AParent;
end;

This appears to just move components from one form to another.

That is correct. A better solution for that would be to put the controls
onto a TFrame, and then re-parent that as needed.

This example:

procedure THostForm.FormCreate(Sender: TObject);
begin
FForm := TChildForm.Create( Self );
FForm.Panel1.Parent := Self;
end;

seemed promising, but it's actually just moving the panel component
from the child form to the parent form. I think.

Yes, it is.

I've tried setting childForm->Parent = parentForm, but this doesn't
seem to have any effect.

It certainly has an effect in VCL. I don't know how FireMonkey handles parent/child
relationships in regards to Form objects, though. AFAIK, in general FireMonkey
allows any object to be embedded inside of any other object.

I can set the childForm position and size when the parentForm is
created or resized, but there doesn't seem to be an OnMove event,
so when the parentForm is moved, the childForm is left behind.

That happens if the childForm's window is not a real child of the parentForm's
window. In FireMonkey, TCommonCustomForm contains the only window handle
that interacts directly with the OS. When a TForm is embedded inside of
another TForm, I don't see FireMonkey's source code setting the childForm's
window to be a child of the parentForm's window, which is likely what is
causing your issue. You will probably have to drop down to the OS API layer
directly and re-parent the child window manually (ie, such as with the Win32
SetParent() function on Windows).

--
Remy Lebeau (TeamB)
Sean Farley

Posts: 9
Registered: 8/10/09
Re: How can I embed a form in another form?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2015 12:32 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
That happens if the childForm's window is not a real child of the parentForm's
window. In FireMonkey, TCommonCustomForm contains the only window handle
that interacts directly with the OS. When a TForm is embedded inside of
another TForm, I don't see FireMonkey's source code setting the childForm's
window to be a child of the parentForm's window, which is likely what is
causing your issue. You will probably have to drop down to the OS API layer
directly and re-parent the child window manually (ie, such as with the Win32
SetParent() function on Windows).

--
Remy Lebeau (TeamB)

Sonofagun. That worked! Thanks Remy!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02