Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: popup in OnExit event cancels execution of OnClick event


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Jun 12, 2017 10:17 AM Last Post By: Remy Lebeau (Te...
Alain Bourgeois

Posts: 26
Registered: 3/15/00
popup in OnExit event cancels execution of OnClick event  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 12, 2017 5:07 AM
Hi,
Using c++ builder XE10 seattle, VCL, win32 application.

I have an edit box with an OnExit event:
void __fastcall TFIDsToStoreWithState::EJobExit(TObject *Sender)
{
    ...
    int i;
    if /* some conditions */  {
       i=Application->MessageBox("warning because ...", "do you want to continue anyway?", MB_YESNO);
       if (i != IDYES) return;
       }
    ... /* display some stuff and make other checks */
}

I have also a Button to save:
void __fastcall TFIDsToStoreWithState::BSaveClick(TObject *Sender)
{
     //... do some stuff...
}


Problem: when focus is on EJob and I click the button AND message "do you want to continue anyway?" is displayed, even if I click Yes, the code in BSaveClick is NEVER executed (setting a breakpoint,: does not reach first line).
So if a popup is displayed in the OnExit code, The OnClick event is cleared from the events list.

Question: is it possible to detect button was clicked so that click code can be executed from OnExit when needed??????

Regards.

Edited by: Alain Bourgeois on Jun 12, 2017 5:08 AM

Edited by: Alain Bourgeois on Jun 12, 2017 5:09 AM
Jan Dijkstra

Posts: 206
Registered: 11/4/99
Re: popup in OnExit event cancels execution of OnClick event  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 12, 2017 6:02 AM   in response to: Alain Bourgeois in response to: Alain Bourgeois
Alain Bourgeois wrote:
Hi,
Using c++ builder XE10 seattle, VCL, win32 application.

I have an edit box with an OnExit event:
void __fastcall TFIDsToStoreWithState::EJobExit(TObject *Sender)
{
    ...
    int i;
    if /* some conditions */  {
       i=Application->MessageBox("warning because ...", "do you want to continue anyway?", MB_YESNO);
       if (i != IDYES) return;
       }
    ... /* display some stuff and make other checks */
}

I have also a Button to save:
void __fastcall TFIDsToStoreWithState::BSaveClick(TObject *Sender)
{
     //... do some stuff...
}


Problem: when focus is on EJob and I click the button AND message "do you want to continue anyway?" is displayed, even if I click Yes, the code in BSaveClick is NEVER executed (setting a breakpoint,: does not reach first line).
So if a popup is displayed in the OnExit code, The OnClick event is cleared from the events list.

Question: is it possible to detect button was clicked so that click code can be executed from OnExit when needed??????

Regards.

It should be possible, yes.

By the time your OnExit code runs, ActiveControl should have been updated to point to the new control that received the focus already. So, in your case, it should be possible, in your OnExit handler, to check if ActiveControl equals your button object.
Alain Bourgeois

Posts: 26
Registered: 3/15/00
Re: popup in OnExit event cancels execution of OnClick event  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 12, 2017 6:20 AM   in response to: Jan Dijkstra in response to: Jan Dijkstra
The problem is that activecontrol is set even if user pushes tabulation without clicking the button.
So it is not enough. I have to know if button has been clicked or not.
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: popup in OnExit event cancels execution of OnClick event [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 12, 2017 8:13 AM   in response to: Alain Bourgeois in response to: Alain Bourgeois
Hi Alain

I made this little example using a message that shows how you might be
able to do it:

#define EDIT_EXIT  WM_APP + 100
bool mouseDown = false;
 
void __fastcall TForm1::EdResultExit(TObject *Sender)
{
   DebugStr( L"EdResultExit" );
   ::PostMessage(Handle, EDIT_EXIT, 0, (long)EdResult );
}
 
void __fastcall TForm1::Button3Click(TObject *Sender)
{
   DebugStr( L"Button3Click" );
}
 
void __fastcall TForm1::Button3MouseDown(TObject *Sender, TMouseButton Button,
   TShiftState Shift, int X, int Y)
{
   mouseDown = true;
   DebugStr( L"Button3MouseDown" );
}
 
void TForm1::editExit( TObject* edit )
{
   if( mouseDown )
   {
      DebugStr( L"editExit mouseDown" );
      mouseDown = false;
      //Do your stof here instead of in the Exit event
   }
 
   DebugStr( L"editExit" );
 
   TEdit* Ed = dynamic_cast<TEdit*>( edit );
   if( ! Ed )return;
 
   Ed->SetFocus();
 
}
 
void __fastcall TForm1::Dispatch( void *Message )
{
   TMessage* msg = (TMessage*)Message;
   switch( msg->Msg )
   {
      case EDIT_EXIT: editExit( (TObject*)msg->LParam ); break;
      default: inherited::Dispatch(Message); break;
   }
}


the result of the above code is:
Debug Output: EdResultExit
Debug Output: Button3MouseDown
Debug Output: editExit mouseDown
Debug Output: editExit
Debug Output: Button3Click

Best regards
Asger
Alain Bourgeois

Posts: 26
Registered: 3/15/00
Re: popup in OnExit event cancels execution of OnClick event [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 12, 2017 8:23 AM   in response to: Asger Joergensen in response to: Asger Joergensen
OK I have to check the mouse is clicked then where the mouse is clicked (to be sure it is on this button).... and raise a flag on this.
Furthermore, it will not work if user only has a keyboard.

Thanks anyway. Code will be set only in onclick, otherwise it will become unmaintainable.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: popup in OnExit event cancels execution of OnClick event [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 12, 2017 10:17 AM   in response to: Alain Bourgeois in response to: Alain Bourgeois
Alain Bourgeois wrote:

Problem: when focus is on EJob and I click the button AND message "do
you want to continue anyway?" is displayed, even if I click Yes, the
code in BSaveClick is NEVER executed (setting a breakpoint,: does not
reach first line). So if a popup is displayed in the OnExit code,
The OnClick event is cleared from the events list.

That is because when OnExit is triggered, the OS is already in the
process of moving input focus to another window, and doing anything
that interfers with that process (ie, displaying another window that
steals the focus) is unsafe, and easily gets the OS out of sync with
itself. So simply don't ever do it.

Question: is it possible to detect button was clicked so that click
code can be executed from OnExit when needed??????

Why are you prompting the user in the OnExit event at all? Don't do
that. It is not standard UI practice to disrupt the user's workflow.
Do the prompt in the button OnClick event instead. If you use the
OnExit event, use it only to display something in your UI that warns
the user that something is wrong, but don't otherwise interfer with
input focus processing:

void __fastcall TFIDsToStoreWithState::EJobExit(TObject *Sender)
{
    ...
    if (/* some conditions */) {
        /* display a warning in the UI */
    }
    ...
    /* display some other stuff and make other checks */
}
 
void __fastcall TFIDsToStoreWithState::BSaveClick(TObject *Sender)
{
    if (/* some conditions */) {
        int i = Application->MessageBox("warning because ...", "do you
want to continue anyway?", MB_YESNO);
        if (i != IDYES) return;
    }
    //... do some stuff...
}


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02