954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Delpi - Embedding forms.

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!

ajst
Junior Poster
121 posts since Nov 2010
Reputation Points: 30
Solved Threads: 3
 

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! :)

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

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.

ajst
Junior Poster
121 posts since Nov 2010
Reputation Points: 30
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: