embedding a FMX forms - delphi

There is some code regarding embedding a FMX form into a panel...
http://docwiki.embarcadero.com/CodeExamples/XE5/en/FMXEmbeddedForm_(Delphi)
....I want to embed multiple forms into the same panel, closing the prior
one of course. I'm having an issue with the proper to close./free those
forms when using the method to embed them from that docwiki.
from testing I have found that the form is not actually embedded but that the objects on the form are moved onto a new parent simulating the effects of an embedded form.
In the vcl this was pretty easy to do but in dmx it's a different ball game.
Any thoughts?

The easiest method to do this is to put a transparent layout on each form as top level component.
When you need to embed a form in your panel, just create an instance of your form and change the parent of it's layout to your panel.
When you don't need the embedded form, you can reparent the layout to its form and free it.

When you embed a form you are, as you state, reparenting some of the components from the embedded form onto the containing form.
If you want to remove those components you can either:
reparent them to something other than the containing form (e.g. back to their original form). Do this if you have multiple forms which you want to be able to swap in and out without having to destroy and recreate all the time.
Free the embedded form (use DisposeOf under ARC). This will both destroy the form and it's controls and remove them from the containing form. (Note that while the containing form becomes the Parent, the original, embedded form stays as the Owner. This the controls are destroyed when the embedded form is destroyed.
You can then create and reparent another form in it's place.
Also note that you can safely embed multiple forms onto one container form but you will need to use a different object as a container for each one. You can also put multiple components or sets of components onto an embeddable form and embed them into separate locations on a container form or even onto multiple forms.
However you can only embed each control(s) into one form at a time.

Related

Copy a TPanel and all of it's Controls at runtime

Delphi-version5.
I have a file comparison app I am putting together and it has a Left and Right Panel on the main form. Each panel (pnlLeft and pnlRight) has an identical range of Controls and events only separated by name. i.e btnCheckLeft(... and btnCheckRight(... and I am having problems keeping the code changes synched between the two Panels.
I am wondering if I can make a single Panel (on a separate Form) with all of the controls and events and then at runtime, copy it twice, once for the pnlLeft an the other, the pnlRight to the main form. On that single Form, I can manage the coding just the once instead of trying to duplicate everything.
During the process, set the Align and the Event names to apply to each copy as in...
The first copy to the blank main form...
pnlLeft.Align:=alLeft;
pnlLeft.Button1Click(Sender)...
the second copy
pnlRight.Align:=alLeft;
pnlRight.Button1Click(Sender)...
How or is that possible? I think I need a Component of the full Panel, but I am not skilled enough to create a Component of this complexity yet.
I checked this
how to copy all the TLabels parented with a TPanel on delphi to another TPanel?
and this
Duplicating components at Run-Time
but don't think either will do what I need.
Thanks for anything you can help with.
The solution to your problem does not lie in duplicating a control at run time. Instead, design a TFrame object. Put all your panel-specific code on there, including any controls it needs. Then, simply instantiate it twice, and give each one a different name. Then you can refer to LeftPanel.btnCheck and RightPanel.btnCheck.

MDI interface with FireMonkey

Is it possible to create an MDI application using FireMonkey in a traditional sense of many documents forms/frames and one master form?
I'm specifically interested since there are no MDI controls on forms anymore.. Has it been replaced with something different?
EDIT: Adding to the question, when I create child forms they all showed separately in taskbar, even the OpenDialogs..
Here's one approach you can use:
1) Create your individual forms as normal, except use a TLayout, call it "LayoutMain", (aligned alClient) as the parent of all controls on that form.
2) On your "master form", when you want to bring a form instance in to behave as it would as an MDI interface, create a TLayout (call it "FormContainer" or something), place as a child of that (aligned to top) another TLayout (call it "FormHeader"), containing the individual controls for the Form Caption, the Minimize/Maximize/Close buttons and anything else you'd like on the "frame" heading. This is called a Composite.
3) Create an instance of your child form (but don't show it), then parent that instance's primary TLayout "LayoutMain" to your main form's TLayout "FormContainer".
4) On the TLayout previously mentioned (with the name "FormHeader"), give it OnMouseDown and OnMouseMove events to provide the ability to drag it around the Master Form.
When you want to maximize the child form inside the master form, you'd just set the outer TLayout "FormContainer" align property to alClient, remembering to store its original Top, Left, Width and Height values within the the form's instance so you can recall them when pressing the Restore button.
True, this is a fairly involved solution, but to the very best of my knowledge this is the only way you're going to achieve what you're trying to do with FireMonkey as it exists today (circa Update 2).
I wouldn't expect Embarcadero to provide any form of MDI emulation as part of FireMonkey "out of the box", as MDI is considered an old-fashioned approach.
The more modern solution would be to use Docking, as the RAD Studio IDE itself does. This provides the very best of both worlds, giving the user the freedom to choose what child forms they want to link into the master form, or display outside of that on their own (or any combination of docked arrangements).

Merge tabs from child form into main form

I have page control in main form and page controls in child form , I
place the child form inside the main form by using docking features.
I am not using MDI style
Now both forms have tabs in page control and I need to merge the child form
tabs into the main form page control, what is the best way to do that?
The simplest and best way to handle multiple tabs on a page control is usually with Frames. Take the contents of each tab and factor them out into an individual frame for each tab. Move any shared components, state and code to a data module. Then just place those frames on the tab sheets of your page control.
This is a fairly simple approach that may or may not suit your needs.
For each child tab page you need to merge:
Create a tab in the main form page
control corresponding to the child
tab
Iterate over the Controls in the
child tab and change the Parent
property to the tab page you just
created
You do not need to deal with controls that are children of other controls. e.g. if you have a groupbox in your child tab, then changing it's parent will bring both it and all controls within it to the new parent.
If you need to be able to "unmerge" your tabs at any point then you will need to devise some mechanism to keep track of where the controls came from so you can restore the original Parent as/when needed.
To make things slightly easier you could place a TPanel in the child tabs, with it's Align property set to alClient. Place all the controls in the tab on that panel and then when you need to merge/unmerge you need only set the Parent of the panel control.
I just tried
procedure TForm1.Button1Click(Sender: TObject);
begin
while Form2.PageControl1.PageCount > 0 do
Form2.PageControl1.Pages[0].PageControl := PageControl1;
end;
and it worked fine. Am I missing something obvious, or why is everybody giving such sophisticated solutions? :-)

how to allow for a flexible UI in ASP.NET MVC

We are starting a new ASP.NET MVC project and we would like to establish a pattern of development that will allow flexibility in the UI. The general idea is that we would like to develop a set of related controls as a unit (i.e. a set of inputs and a submit button) and maintain the flexibility to decide later 1 of 3 UI options
Have that set of controls with its submit button be alone on a web page, OR
Have the set of controls be together with other sets of controls on the same page, and each set has its own submit button, OR
Have the set of controls be together with other sets of controls on the same page, but there is only one submit button for the whole page
Is there any pattern or strategy of development that would allow us to develop with this flexibility?
I would create a Partial view for this scenario. Just lay out the form in your Partial view and drop it into whichever view you see fit.
Since the entire body is not wrapped in a form tag like WebForms, there is no limit to the number of forms you can use on a page as long as they're not nested.
This one is a bit tougher. Unlike WebForms where you could put controls all over the page and have a button click collect those you can't do that with MVC. Your options would be to make sure the inputs are within a form or use JavaScript to collect all the values and submit those.

AlphaBlend a child form

I'm looking after a way to AlphaBlend a child form, if possible using layered windows as there will be interactive controls behind it.
The problem is I have a component in a regular TForm that paints multiple visual layers (drawings, pictures...). At some point I need to instantiate an editor control on this form (in-place), this control will involve a variety of standard input controls outside of my control (edit box, check box, etc.), however I would like to overlay the layers in front of the layer being edited using alpha blending (and WS_EX_TRANSPARENT to make it click-through).
I first thought of using child forms for that (borderless TForms parented to the component), and that works alright, up to the point where the AlphaBlended TForm isn't alphablended at all, but turns opaque as soon as parented...
I then tried to unparent the alphablended form, set it to fsStayOnTop, and by reacting to the relevant events, keep it in front of the component on screen, that works, but that isn't a truly satisfying solution: the alphablended StayOnTop form is also in front of other modal and modeless forms of the application, should the user decide to move them in front of the component...
So, any other ideas on a way to have a child form be alphablended? (or behave like it is)
According to MSDN you are out of luck, as WS_EX_LAYERED cannot be used for child windows.
Maybe you could hide all editor forms when your form / application loses focus, that would at least keep them from being on top of other windows. Still, it's unsatisfactory...

Resources