AuthorMessage
Mickey
Ametuar
Posts: 115

We know how important is for applications to use as much less memory as they can.
Just imagine if we have an application with a lot of forms 50-100 all of them are on heap. (static variables). We call these forms with Form1.Show, Form2.Show ... etc.
In Delphi we can make them dynamic easy. I will show in a few steps.
Let’s suppose that we have a project with n forms.
Form1, Form2, Form3 ... FormN.
If Form1 is our main form, which is always created on startup. We can make Form2 – FormN dynamic (not alocating any memory on heap only when they are needed/shown).
To do this go to “Project” menu ---> “Options” ---> “Forms” tab.
You can see Main form, Auto-create forms, Available forms.
Select
Main form := Form1
Move Form2 – FormN from "Auto-create forms" list to "Available forms" list and press OK.
Screenshots:
Quote:
  Form2.Show;
will give error because the form does not exist. It is good because not allocating memory on heap. Whenever we need to display a form we can do in several ways:
Quote:
  Form2 := TForm2.Create(Self);  // Creating
  Form2.Show;                // Displaying
  Form2.Free;                  // Freeing. Will return here after the form is closed.
...
  Form3 := TForm3.Create(Self);
  Form3.ShowModal;
  Form3.Free;
...
  Form4 := TForm4.Create(Self);
  Form4.ShowModal=mrOK;
  Form4.Free;

That’s all folks.