Answer the question
In order to leave comments, you need to log in
How to close the program correctly?
Hello!
How to close the program correctly?
Now it works for me in such a way that when I click the cross on the form, it collapses to tray, and the close button itself is implemented in the PopupMenu:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
//не закрываем а сворачиваем в трей
CanClose := false;
TrayIcon1.Visible := true;
Form1.Visible := false;
ShowWindow(Application.Handle, SW_HIDE);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey (Form1.Handle, 0);
TrayIcon1.Free;
Image1.Free;
Self.Free;
end;
procedure TForm1.N4Click(Sender: TObject); //кнопка закрыть
begin
//halt;
Application.Terminate;
end;
procedure TForm1.ApplicationEvents1Minimize(Sender: TObject); //сворачивание окна
begin
Form1.Visible := false; // Делаем форму невидимой
TrayIcon1.Visible := True; // Делаем иконку с трее видимой
end;
Answer the question
In order to leave comments, you need to log in
1. You don't need to destroy/release components that are created through the designer or with an Owner. Such components will free themselves.
2. FormDestroy - called when the form is destroyed, and you are again trying to cause the form to be destroyed. It can even be logically understood.
3. Application Terminate; - normal closing of the program. This method sets a flag to terminate the program. And the program will close as soon as the message queue ends.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question