Forms Delphi

Title: Embeded Forms
Question: Embeded Forms
Answer:
Two months ago I have start coding a analisys program. The hard part of this program wasn't the application logic, as you expect. The real hard part was the user interface. That's because, the user need to manual set approx. 200 parameters. That's means 200 edit boxes (oh, my God!).
This 200 editBoxes are separated in 24 clases of interest. Simply, you'll say. It's a good idea to use a page control, a notebook or some like that. But, just imagine. The program with 200 editboxes, with entire conections, verifications, analisys, all put in a single unit can be your very bad programming experience.
So I have decided to seaprate the user entry data in 24 forms. Look good, but here was my second deception. Using a display form command like show or showModal was not a solution. Also, a MDI application was rejected because the customer doesn't like it.

The best solution I have decided to use was Embede Forms. What that means? The best way to improve your programming style. Why?
First: all the user interface is divided in different forms, so the application logic is easy to control.
Second: when use embeded forms, you save a lot of memory. The difference you'll see only if you have many controlsn on forms.
And now, let's see how embeded works:
First of all you need a global variable to store the current form:
MyForm: TForm;
You put all controls you need in project on different forms instead of putting then on diffrent notebook pages. In the Project | Options menu don't forget to remove your embede forms from AutoCreate List. Anytime when you need a form you simply create it like bellow:
MyForm:=TForm2.Create(Application);
and set some properties (see bellow):
with MyForm do
begin
BorderIcons:=[];
BorderStyle:=bsNone;
parent:=panel1; //THIS IS MOST IMPORTANT!
//YOU SET PANEL1 AS THE PARENT OF YOUR FORM
Align:=alClient;
visible:=true;
end;
Now you have a complete idea about creating a Embede Form at run-time. But the problem start now. What's happend if you want to create another form? First you need to free the current form and then create your next form. For do this, the best method is to create a procedure used to free the current opened form:
procedure TForm1.FreeCurrentForm;
begin
if MyFormnil then MyForm.Free;
end;
Every time when you want to create a new form call first teh FreeCurrentForm procedure. And that's all folks!