1. How to ensure the release of the memory form?
When creating a form, according to the code below, I need to destroy it somehow when it is finished by the user?
F_PesqCli := TF_PesqCli.Create(self);
The builder Create
object pattern TComponent
in Delphi receives by parameter (AOwner: TComponent)
If you pass the Owner
as Self
, you are saying that the current instance of where the code is owner of the component created, in the case of TForm
. So when that Owner is destroyed, the form will also be.
If you want, when the user finishes a form, that it is destroyed, in the event onClose
form just you set the desired action
Action := caFree;
Another measure is to manage the window life cycle Modal
during their initialization:
Form := TForm.Create(nil);
try
Form.ShowModal;
finally
Form.Free;
end;
2. How to ensure that a window is not opened twice?
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 image example below?
The Main Form must be set to the property FormStyle
for fsMDIForm
Children must have the parent form as Owner and FormStyle
for fsMDIChild
Perfect, that’s exactly what I needed. Thank you very much
– Giovani