Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: MesssageBox line of code being skipped. C++ Builder XE



Permlink Replies: 7 - Last Post: Feb 17, 2015 2:51 PM Last Post By: sean collins
sean collins

Posts: 9
Registered: 5/22/13
MesssageBox line of code being skipped. C++ Builder XE
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2014 11:27 AM
I'm fairly new to programming so forgive any gaffes in terminology. I have a few Application->MessageBox()'s in a function and sometimes, at least one of the message box lines are being skipped as if they do not exist in the code, as can be seen when stepping through in debug mode. (It happens in release mode as well). This has happened in more than one project and any help would be a life saver. Thanks.

void __fastcall TForm1::Button2Click(TObject *Sender)
{
//create claims
int lstgrpno=0,lstempno=0,lstdepno=0,lstprvno=0,lstsuff=0,lstfundyr=0;
int clmln=0;
int claimno=0;
double chgamt = 0,
prvpmt = 0,
eepmt = 0;
TDateTime fromdt, thrudt;
String sql, filter;

if (button_flag !=1 ){
Application->MessageBox(L"Add/Modify button has not been run.", PROGNAME, MB_OK);
return;
}
if (Application->MessageBox(L"Would you like to see transmittal report?", PROGNAME, MB_YESNO|MB_SYSTEMMODAL) == ID_YES) {
//RUN'S A QUERY AND A REPORT COMPONENT HERE
}

if (Application->MessageBox(L"THIS MESSAGE BOX GETS SKIPPED AND THE COMPILER WILL NOT STEP INTO THE IF STATEMENT", PROGNAME, MB_YESNO|MB_SYSTEMMODAL) == ID_YES) {
// DOES WORK IN THE DATABASE HERE
}
}

Edited by: sean collins on Oct 7, 2014 11:29 AM
In testing I've noticed that if I answer NO to the first prompt ("Would you like to see transmittal report?"), that the second prompt will appear and allow you to answer yes or no. If you say YES to the first prompt, you will not get the second prompt.

Edited by: sean collins on Oct 7, 2014 11:41 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: MesssageBox line of code being skipped. C++ Builder XE [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2014 12:44 PM   in response to: sean collins in response to: sean collins
sean wrote:

In testing I've noticed that if I answer NO to the first prompt
("Would you like to see transmittal report?"), that the second
prompt will appear and allow you to answer yes or no. If you
say YES to the first prompt, you will not get the second prompt.

That implies that the code in the "RUNS A QUERY" section is most likely exiting
from Button2Click(), either with a 'return' or throwing an exception, before
the second MessageBox() can be called.

--
Remy Lebeau (TeamB)
sean collins

Posts: 9
Registered: 5/22/13
Re: MesssageBox line of code being skipped. C++ Builder XE [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2014 12:48 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
sean wrote:

In testing I've noticed that if I answer NO to the first prompt
("Would you like to see transmittal report?"), that the second
prompt will appear and allow you to answer yes or no. If you
say YES to the first prompt, you will not get the second prompt.

That implies that the code in the "RUNS A QUERY" section is most likely exiting
from Button2Click(), either with a 'return' or throwing an exception, before
the second MessageBox() can be called.

--
Remy Lebeau (TeamB)

Thanks for the quick reply. No, that is not the case. When stepping through the code in DEBUG mode, it is not exiting. It hits the IF() with the message box in it then keeps going as if the IF() == false. No message box is displayed. Keeps going through the rest of the function.
sean collins

Posts: 9
Registered: 5/22/13
Re: MesssageBox line of code being skipped. C++ Builder XE [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2014 12:50 PM   in response to: sean collins in response to: sean collins
sean collins wrote:
Remy Lebeau (TeamB) wrote:
sean wrote:

In testing I've noticed that if I answer NO to the first prompt
("Would you like to see transmittal report?"), that the second
prompt will appear and allow you to answer yes or no. If you
say YES to the first prompt, you will not get the second prompt.

That implies that the code in the "RUNS A QUERY" section is most likely exiting
from Button2Click(), either with a 'return' or throwing an exception, before
the second MessageBox() can be called.

--
Remy Lebeau (TeamB)

Thanks for the quick reply. No, that is not the case. When stepping through the code in DEBUG mode, it is not exiting. It hits the IF() with the message box in it then keeps going as if the IF() == false. No message box is displayed. Keeps going through the rest of the function.
Additionally, if I place another message box in between the existing two, just for testing, the test message box is skipped and the next one gets executed now. It will only skip on message box when this happens and will execute the next one in line.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: MesssageBox line of code being skipped. C++ Builder XE [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2014 1:29 PM   in response to: sean collins in response to: sean collins
sean wrote:

Additionally, if I place another message box in between the existing
two, just for testing, the test message box is skipped and the next
one gets executed now. It will only skip on message box when this
happens and will execute the next one in line.

That implies that there are lingering messages/keystrokes in the calling
thread's message queue that are cancelling the next dialog to be displayed.

--
Remy Lebeau (TeamB)
Sean Hoffman

Posts: 126
Registered: 3/28/99
Re: MesssageBox line of code being skipped. C++ Builder XE
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2014 1:40 PM   in response to: sean collins in response to: sean collins
You can also generally use the Windows functions OutputDebugString, OutputDebugStringA (for Ansi character set), and OutputDebugStringW (for wide character strings) to do debugging output. Using these (rather than the message box method) shouldn't affect your program's Windows message Queue. While running the program in the debugger, C++ Builder will capture the output and display it in one of the debug windows (I forget which one and I'm not near my Windows machine at the moment; you may have to open it up for viewing). Note that if you're not running the program in the debugger, you'll have to use something like sysinternals debugview to watch the debugging output. Also note that since many other Windows apps also use OutputDebugString*, so don't be surprised if you see "production" versions of other apps on your system (including some from Microsoft) where the developers were sloppy and left that stuff in before shipping their applications, leading to additional output that you didn't put there. Just ignore that stuff (if possible).

Edited by: Sean Hoffman on Oct 7, 2014 3:40 PM

Edited by: Sean Hoffman on Oct 7, 2014 3:42 PM
sean collins

Posts: 9
Registered: 5/22/13
Re: MesssageBox line of code being skipped. C++ Builder XE
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 8, 2014 5:23 AM   in response to: sean collins in response to: sean collins
sean collins wrote:
I'm fairly new to programming so forgive any gaffes in terminology. I have a few Application->MessageBox()'s in a function and sometimes, at least one of the message box lines are being skipped as if they do not exist in the code, as can be seen when stepping through in debug mode. (It happens in release mode as well). This has happened in more than one project and any help would be a life saver. Thanks.

void __fastcall TForm1::Button2Click(TObject *Sender)
{
//create claims
int lstgrpno=0,lstempno=0,lstdepno=0,lstprvno=0,lstsuff=0,lstfundyr=0;
int clmln=0;
int claimno=0;
double chgamt = 0,
prvpmt = 0,
eepmt = 0;
TDateTime fromdt, thrudt;
String sql, filter;

if (button_flag !=1 ){
Application->MessageBox(L"Add/Modify button has not been run.", PROGNAME, MB_OK);
return;
}
if (Application->MessageBox(L"Would you like to see transmittal report?", PROGNAME, MB_YESNO|MB_SYSTEMMODAL) == ID_YES) {
//RUN'S A QUERY AND A REPORT COMPONENT HERE
}

if (Application->MessageBox(L"THIS MESSAGE BOX GETS SKIPPED AND THE COMPILER WILL NOT STEP INTO THE IF STATEMENT", PROGNAME, MB_YESNO|MB_SYSTEMMODAL) == ID_YES) {
// DOES WORK IN THE DATABASE HERE
}
}

Edited by: sean collins on Oct 7, 2014 11:29 AM
In testing I've noticed that if I answer NO to the first prompt ("Would you like to see transmittal report?"), that the second prompt will appear and allow you to answer yes or no. If you say YES to the first prompt, you will not get the second prompt.

Edited by: sean collins on Oct 7, 2014 11:41 AM

That was it, the report that is being run in the previous if has a page status window that was not closing and stuck behind the main form.
Thanks very much for the help!!!
sean collins

Posts: 9
Registered: 5/22/13
Re: MesssageBox line of code being skipped. C++ Builder XE
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 17, 2015 2:51 PM   in response to: sean collins in response to: sean collins
sean collins wrote:
sean collins wrote:
I'm fairly new to programming so forgive any gaffes in terminology. I have a few Application->MessageBox()'s in a function and sometimes, at least one of the message box lines are being skipped as if they do not exist in the code, as can be seen when stepping through in debug mode. (It happens in release mode as well). This has happened in more than one project and any help would be a life saver. Thanks.

void __fastcall TForm1::Button2Click(TObject *Sender)
{
//create claims
int lstgrpno=0,lstempno=0,lstdepno=0,lstprvno=0,lstsuff=0,lstfundyr=0;
int clmln=0;
int claimno=0;
double chgamt = 0,
prvpmt = 0,
eepmt = 0;
TDateTime fromdt, thrudt;
String sql, filter;

if (button_flag !=1 ){
Application->MessageBox(L"Add/Modify button has not been run.", PROGNAME, MB_OK);
return;
}
if (Application->MessageBox(L"Would you like to see transmittal report?", PROGNAME, MB_YESNO|MB_SYSTEMMODAL) == ID_YES) {
//RUN'S A QUERY AND A REPORT COMPONENT HERE
}

if (Application->MessageBox(L"THIS MESSAGE BOX GETS SKIPPED AND THE COMPILER WILL NOT STEP INTO THE IF STATEMENT", PROGNAME, MB_YESNO|MB_SYSTEMMODAL) == ID_YES) {
// DOES WORK IN THE DATABASE HERE
}
}

Edited by: sean collins on Oct 7, 2014 11:29 AM
In testing I've noticed that if I answer NO to the first prompt ("Would you like to see transmittal report?"), that the second prompt will appear and allow you to answer yes or no. If you say YES to the first prompt, you will not get the second prompt.

Edited by: sean collins on Oct 7, 2014 11:41 AM

That was it, the report that is being run in the previous if has a page status window that was not closing and stuck behind the main form.
Thanks very much for the help!!!
Application->ProcessMessages(); resolved the issue.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02