Hi DaniWeb,

I'm new to delphi and was wondering if it is possible to embed forms inside one another.

Example
I have several forms working by it self and I want to move them forms onto a new blank form.

Rather then copying and pasting the code is there a way I can embed these forms into my blank form? so say on the left hand side I have form 1 and right hand side form 2 but are inside the blank form.

hope that makes sense.

Thanks in Advance!

It is possible but very prone to error. This code shows how you can switch out a form in a panel in a button click event:

procedure TMainStockForm.StockTakeBtnClick(Sender: TObject);
begin
	LockWindowUpdate(Self.Handle);
        Panel1.Visible := true;
        try
	    StockTakeBtn.Down := true;
	    StockTakeForm.WindowState := wsMaximized;
	    StockTakeForm.ShowForm;
	    ShowWindow(StockTakeForm.Handle,SW_SHOWMAXIMIZED);
        finally
	    Panel1.Visible := false;
            LockWindowUpdate(0);
        end;
end;

Make sure your inner form (StockTakeForm in my example) does not rely on a ModalResult.

Having said this, I think it is a much better option to put all of your "inner form" code inside a page control and switch tabs. Two inner forms in a single form at the same time probably won't work, but you could just use panels or page controls for this too.

Anyway have a play with the example and see how you go. Good luck! :)

Thank you for the reply, but I found and worked on a solution before you posted.

This is for a project where you can interact with the objects and edit them at run time. So In the end I used my canvas as a MDI Parent then create MDI Children at run time but hide the window frames so they do not look like windows and look just like the forms.

If anyone else gets stuck with this I would be happy to post my code if needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.