Delphi OnClose Event in DelphiVCL Library

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,203
Credits
4,034
OnClose Event in DelphiVCL Library
By Muhammad Azizul Hakim June 1, 2021

OnClose event occurs when the form closes.

We use OnClose to perform special processing when the form closes. The OnClose event specifies which event handler to call when a form is about to close. The handler specified by OnClose might, for example, test to make sure all fields in a data-entry form have valid contents before allowing the form to close.

A form is closed by the Close method or when the user chooses Close from the form’s system menu.

The TCloseEvent type points to a method that handles the closing of a form. The value of the Action parameter determines if the form actually closes.

These are the possible values of Action:

ValueMeaning
caNoneThe form is not allowed to close, so nothing happens.
caHideThe form is not closed, but just hidden. Your application can still access a hidden form.
caFreeThe form is closed and all allocated memory for the form is freed.
caMinimizeThe form is minimized, rather than closed. This is the default action for MDI child forms.
If a form is an Для просмотра ссылки Войди или Зарегистрируйся, and its BorderIcons property is biMinimize, then the default Action is caMinimize. If an MDI child form does not have these settings, the default Action is caNone, meaning that nothing happens when the user attempts to close the form.

If a form is an SDI child form, Action defaults to caHide.

To close the form and free it in an OnClose event, set Action to caFree.

Note: When the application shuts down, the main form receives an OnClose event, but any child forms do not receive the OnClose event.

Here is the working example of the implementation of an OnClose event like in the Section 7 (Getting Started with DelphiVCL III: Overview of Commonly used VCL Components):
Python:
self.OnClose = self.MainFormClose