Forum > LCL

BitBtn bkClose closes window even though ModalResult is mrNone. Bug or feature?

(1/3) > >>

Aidex:
Hello!
I've placed a TBitBtn on a form, choose bkClose kind, but want to handle OnClick myself, so I've set the button's modalresult to mrNone.
I hoped mrNone would prevent automatically closing the form, but the window closes before I can handle the button's OnClick event.
As I understood mrNone, it shouldn't close a form.

wp:
You must set the ModalResult of the Form to prevent the form from closing.

Aidex:
Form's ModalResult is mrNone! (default)
There's no change when I set Form.ModalResult:=mrNone at runtime or in BitBtn.OnClick() event.
The form will be closed anyway!

wp:
It *is* working - I do this all the time for error checking before a form can close. See attached demo.

Maybe my description was too short: you must use the OnClick event of the form to set its ModalResult to mrNone in order to prevent closing of the form. Having clicked on the OKButton has changed the form's Modalresult to the ModalResult of the button. Therefore, the form closes when the OnClick handler exits. Setting the form's ModalResult back to mrNone prevents closing the form.

Aidex:
Oh yes, in your example it's working - because the button is not on the main form.
But in my program the button is on Form1 and it always closes the program.  :(
I can reproduce it in your example program, too, when I copy the button from Form2 to Form1
(also after setting button's ModalResult to mrNone)

Navigation

[0] Message Index

[#] Next page

Go to full version