February 26th, 2013, 08:17 AM
Confirm (or not) TForm Close [lazarus/pascal]
Is there some way to interupt the Close function of a form and pop up a confirmatoin dialog?
When File->Exit is selected from my main form I run a couple of checks to make sure the user has saved any changes they have made in the application. The user is presented with a MessageDLG asking i fthey are sure they want to exit - and the application only closes if they respond mrYes.
That works fine but I'd like to call the same routine when the top right (in Windows) close button is clicked.
I can get the checks and dialog to be called by setting that functoin in the OnClose event for the main TForm, but this does not allow me to cancel the application closing when the user clicks mrNo.
I get the feeling this is either going to be really easy and I'll feel stupid for asking, or it's going to be difficult (for me as a newbie to lazarus and pascal) to implement.
PS I have experience in the past with Borland C++ builder, but am new to the quirks of pascal in lazarus.
February 26th, 2013, 09:01 AM
Proving the rule that no matter how long you've been looking, as soon as you post a question on a forum you'll find the answer yourself...
The OnCloseQuery event was staring me in the face... I've used that and set CanClose to true or false depending on the MessageDLG response.