943,964 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 18953
  • C++ RSS
Oct 22nd, 2004
0

Calling MessageBox in Borland C++Builder

Expand Post »
Hello everyone,
I don't often use forums for getting answers, but I simply cannot seem to find how to fire a MessageBox under Borland Builder...I could use MessageDlg which works, but I only want an OK button, so I would rather go with MessageBox...code sample:
C++ Syntax (Toggle Plain Text)
  1. void __fastcall TForm1::cmdPlayClick(TObject *Sender)
  2. {
  3. if (TForm1::txtLogin->Text=="")
  4. {
  5. ::MessageBox("Invalid Login Name!", "Error!", MB_OK, 0);
  6. return;
  7. }
With MessageDlg:
C++ Syntax (Toggle Plain Text)
  1. if (TForm1::txtPass->Text=="")
  2. {
  3. MessageDlg("Invalid Password!", mtError, mbOKCancel, 0);
  4. return;
  5. }
  6. TForm1::LoadLauncher();
  7. }
NOTE: I know it defines mbOK as a variable for TMsgDlgButtons, but it fires an error that it's NOT a recognized variable...I may be overlooking something, but it's late and I've been coding for hours now just getting my ActiveX control to function without causing access violations at memory address 0x000000 (WideString function is your friend.) Next issue will be writing the code to open a file which is like an ini file, but has a different structure (ie: no "[]" but uses "=" as an assignment operator...I *think* I have the groundwork set, but am unfamiliar with C++ file manipulation, I had created a similar program in VB6 and the styles of coding are mixing in my head =)

Thanks in advance for any information.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Pretorak is offline Offline
2 posts
since Oct 2004
Oct 22nd, 2004
0

Re: Calling MessageBox in Borland C++Builder

I don't have my Builder up anymore, but replace MB_OK with zero and see what happens.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 22nd, 2004
0

Re: Calling MessageBox in Borland C++Builder

*sigh*
I found my error, in Borland's help files, it gives an example of:
C++ Syntax (Toggle Plain Text)
  1. Application->MessageBox(const WideString Text, const WideString Caption,
  2. TMessageButtons Buttons = TMessageButtons() << smbOK,
  3. TMessageStyle Style smsInformation, TMessageButton Default = smbOK,
  4. TMessageButton Escape = smbCancel);
My error was using it in my Unit1.cpp file. Since all my declarations and main code is in the header file, it gave mystery errors and I tried various implementations like TApplication::MessageBox(blah) and stopped getting errors with plain ::MessageBox(blah) I moved the code into my header file and it now works. snippet for future reference:
C++ Syntax (Toggle Plain Text)
  1. Application->MessageBox("Message", "Title", Buttons() << btnValue);
  2. //btnValue is MB_OK, etc. for the various button styles.
Like I said previously, it was late and I had the too-many-hours-coding-brain-lock syndrome to recognize that issue. Figured I would reply with my fix. Thanks for your help...off to build my file handling routines =)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Pretorak is offline Offline
2 posts
since Oct 2004
Sep 8th, 2007
0

Re: Calling MessageBox in Borland C++Builder

Hi,

Try this

if( MessageBox(0, (LPSTR) "testing", "Error",
MB_ICONWARNING | MB_OK ) ==MB_OK) //do whatever



regards

Bob


Click to Expand / Collapse  Quote originally posted by Pretorak ...
Hello everyone,
I don't often use forums for getting answers, but I simply cannot seem to find how to fire a MessageBox under Borland Builder...I could use MessageDlg which works, but I only want an OK button, so I would rather go with MessageBox...code sample:
C++ Syntax (Toggle Plain Text)
  1. void __fastcall TForm1::cmdPlayClick(TObject *Sender)
  2. {
  3. if (TForm1::txtLogin->Text=="")
  4. {
  5. ::MessageBox("Invalid Login Name!", "Error!", MB_OK, 0);
  6. return;
  7. }
With MessageDlg:
C++ Syntax (Toggle Plain Text)
  1. if (TForm1::txtPass->Text=="")
  2. {
  3. MessageDlg("Invalid Password!", mtError, mbOKCancel, 0);
  4. return;
  5. }
  6. TForm1::LoadLauncher();
  7. }
NOTE: I know it defines mbOK as a variable for TMsgDlgButtons, but it fires an error that it's NOT a recognized variable...I may be overlooking something, but it's late and I've been coding for hours now just getting my ActiveX control to function without causing access violations at memory address 0x000000 (WideString function is your friend.) Next issue will be writing the code to open a file which is like an ini file, but has a different structure (ie: no "[]" but uses "=" as an assignment operator...I *think* I have the groundwork set, but am unfamiliar with C++ file manipulation, I had created a similar program in VB6 and the styles of coding are mixing in my head =)

Thanks in advance for any information.
Reputation Points: 8
Solved Threads: 1
Newbie Poster
robgxxx is offline Offline
9 posts
since Jun 2005
Sep 8th, 2007
0

Re: Calling MessageBox in Borland C++Builder

Sorry I've just seen that I made a boob, the code
should have been ...

if(MessageBox(0, (LPSTR) "testing","Error",
MB_ICONWARNING | MB_OKCANCEL ) ==IDOK) //do whatever


regards

Bob G
Reputation Points: 8
Solved Threads: 1
Newbie Poster
robgxxx is offline Offline
9 posts
since Jun 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: numbering code lines
Next Thread in C++ Forum Timeline: software





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC