Delphi 10.3 Creating FMX forms inside another FMX form close error


I’ve followed this:

and this:

and this:

I’m using Delphi 10.3

My final result was: I’ve created a parent form with a TLayout inside of it where I want the child forms to appear. Next, all my child forms have a TLayout containing all the other components of the form. All forms are dynamically created in runtime and their contents are as well.

For testing purposes I’ve created the childform inside a button on the main form:

procedure TForm1.Button1Click(Sender: TObject);
Application.CreateForm(TfChild, fChild);
fChild.Layout1.Parent := self.Layout1;

So far so good, all the components of the childform appears on the parent form. Problem is, how to “clear” them afterwards. Sending a self.Close, on a button on the child form doesn’t remove the Layout components from the main form but it closes the child form. Doing a Layout1.Destroy on the child form’s button clears the layout, but I lose acess to my main form’s window control buttons (maximize, minimize, exit) and the only way to get that access back is to recreate the child’s layout.
This embedded feature I only wanna use for windows and macos OS’, for android it won’t be necessary so I’m using defs to adjust that.

I feel like I’m not doing this the right way :'(, is there a solution? I just want to dynamically create the components of a child form inside the main form’s designated area and have a safe way of clearing those components after that child form is no longer necessary

Comments are closed.