How to detect the application is about to terminate?

324 views Asked by At

I'm working on a VCL application which communicates over bluetooth with a microcontroller and I want to execute a code right before the application terminates.

How can I detect the application is about to terminate ?

1

There are 1 answers

3
M.M On BEST ANSWER

Write a handler for the OnClose event of your main form. The reference describes the app. shutdown notification as:

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

The code will be executed when the form is closed by any means (other than the process being killed or segfaulting etc.)