#1
  1. No Profile Picture
    The Monk that is Fat.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    UK
    Posts
    107
    Rep Power
    14

    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.

    Thanks,

    FM

    PS I have experience in the past with Borland C++ builder, but am new to the quirks of pascal in lazarus.
  2. #2
  3. No Profile Picture
    The Monk that is Fat.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    UK
    Posts
    107
    Rep Power
    14
    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.

    Job done.

    -FM

IMN logo majestic logo threadwatch logo seochat tools logo