When you add a new form in Lazarus project, it will be created automatically when application starts.
If you want to create forms only when needed to reduce memory consumption, or to create many instances of that form during application execution, you can create it at run time using the following procedures:
Suppose that your form name is fmSecondForm
- Remove the form from Auto-create forms list in Project Options/Forms, and put it in Available forms
2. At Form’s OnClose event write this code to free this instance when closing it:
3. Whenever you need to create this form write this code :
procedure TfmFirst.Button1Click(Sender: TObject); var MyForm: TfmSecondForm; begin MyForm:= TfmSecondForm.Create(Application); MyForm.Show; end;