Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel Button - Mysterious loss of Event 1

Status
Not open for further replies.

KNMn

Programmer
Jun 29, 2006
6
0
0
AU
In certain circumstances within the application which I wrote in C++ Builder 4/5, a dialog cannot be closed by pressing its cancel button. Generally I just click the Cancel button or press escape (ie I have the "Cancel" property of the button set to true) to close the dialog. The event handler for the close button calls Hide(), but I have also tried, SetFocus(), Update(), Visible = FALSE, just to name a few. I have come to the conclusion that when the problem occurs my event handler is not being called when the button is clicked. ie somehow the Event seems to be getting lost!!??? (The problem doesn't occur when running in the debug environment).

Has anybody experienced similar behaviour or have any suggestions for a possible remedy?
 
I've never seen this but I always use close instead of cancel. Have you tried that?

If that doesn't help, try posting some code here.


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
I tried your suggestion of using Close(), but am still experiencing the same behaviour. The close event seems to be being directed away from my event handler.

void __fastcall TmodemConnectDlg::CancelBtnClick(TObject *Sender)
{
// SetFocus();
// Update();
// Hide();
// Update();

Close();
}
//---------------------------------------------------------------------------

 
In the button properties, your mention that Cancel set to true. Try changing it to false and see what happens. It's possible the cancel function is overriding what you put in the code.

Just out of curiosity, why don't you use MessageBox or MessageDlg?

James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
I tried setting Cancel to false also, but no help. I suspect you are onto something though because the other buttons on the form work OK, even when the Cancel function doesn't!

I've tried playing with the tabstop number also, and then even adding another button to the form with its on-click event handler calling Close(). But still the same result. I added tracing to the close button event. The tracing is being called, so contrary to my earlier theory the event is not being hijacked. So something is disabling the form's capacity to close? Clicking on the main form and then back to this dialog makes it work properly again.
Any further clues?

FYI - I didn't use MessageBox etc since in this case the form originated from the Borland Generic Password entry form, and I needed this password feature.


 
As a test, can you create a new form from scratch with just a close button? That way we can see if something went bonkers during the form's original setup.


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
I solved the problem of the cancel button with the following code.

Visible = true;
SetFocus();
Close();

I have since discovered similar behavour on another form which has no buttons. (In this case I am overloading the Hide() function. I tried adding Visible=true and SetFocus(), similar to what helped the other form. Now one of its derived forms works OK, but another has started to fail.

This problem is really starting to smell of corruption or configuration, since this software never had the problem for the last two years!

Also the problem has never occured when running in the development environment.

Recently I have moved to a new computer running XP not 2000. Maybe this has an affect.

Is there anything that needs to be done for operation on XP?

 
The calls for 2000 and XP should be the same since they are very "similar behind the scenes." I've been writing programs for both 2000 and XP without having to make any changes to the program.



James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top