1. How to ensure release of form from memory?
When creating a form, according to the code below, do I need to destroy it in some way when it is finished by the user?
F_PesqCli := TF_PesqCli.Create(self);
The Create
default constructor of the TComponent
objects in delphi is received by (AOwner: TComponent)
If you pass Owner
to Self
, you are saying that the current instance of where the code is is the donor of the created component, in this case TForm
. So when this Owner is destroyed, the form will also be destroyed.
If you want the user to terminate a form, that it is destroyed, in the event onClose
of the form you just have to set the desired action
Action := caFree;
Another measure is to manage the lifecycle of the Modal
windows during their startup:
Form := TForm.Create(nil);
try
Form.ShowModal;
finally
Form.Free;
end;
2. How to ensure that a window is not opened doubly?
The safest way is to validate those already created in the application
function ValidaFormJaCriado(const ClassDoForm: TClass): Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to Screen.FormCount - 1 do
begin
if Screen.Forms[I].Class = ClassDoForm then
begin
Result := True;
Break;
end;
end;
end;
3. How do I minimize a form internally, as in the example image below?
The Main Form must be set to FormStyle
property to fsMDIForm
The child forms must have the parent form as Owner and FormStyle
to fsMDIChild