Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: How to distinguish among buttons in FormCloseQuery



Permlink Replies: 2 - Last Post: Dec 7, 2017 12:41 PM Last Post By: Greg Reese Threads: [ Previous | Next ]
Greg Reese

Posts: 85
Registered: 7/15/05
How to distinguish among buttons in FormCloseQuery
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 6, 2017 6:57 AM
I have a FireMonkey form with a cancel button and an okay button on it. The form has the FormCloseQuery event handler

void __fastcall Form1::FormCloseQuery(TObject *Sender, bool &CanClose)


Is there a way to tell from within the handler which button was pushed? It looks like sender is the address of the form itself, not a button. I could program this effect by using the buttons' OnClick events but I'm wondering if there's a built-in technique.

Thanks.

Greg Reese
Remy Lebeau (Te...


Posts: 8,950
Registered: 12/23/01
Re: How to distinguish among buttons in FormCloseQuery
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 7, 2017 10:52 AM   in response to: Greg Reese in response to: Greg Reese
Greg Reese wrote:

Is there a way to tell from within the handler which button was
pushed? It looks like sender is the address of the form itself, not a
button. I could program this effect by using the buttons' OnClick
events but I'm wondering if there's a built-in technique.

A button closes its parent Form only if the Form is being shown modally
and the button has a ModalResult assigned. The Form closes itself when
its ModalResult property is set to a non-zero value. Your Form's
OnCloseQuery handler can look at the Form's ModalResult property to see
which button ModalResult value was assigned to it.

--
Remy Lebeau (TeamB)
Greg Reese

Posts: 85
Registered: 7/15/05
Re: How to distinguish among buttons in FormCloseQuery
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 7, 2017 12:41 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
A button closes its parent Form only if the Form is being shown modally
and the button has a ModalResult assigned. The Form closes itself when
its ModalResult property is set to a non-zero value. Your Form's
OnCloseQuery handler can look at the Form's ModalResult property to see
which button ModalResult value was assigned to it.

--
Remy Lebeau (TeamB)
Perfect. Thanks Remy.
Greg Reese
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02