Your full service technology partner! 
-Collapse +Expand
Search Delphi Group:

-Collapse +Expand Delphi To/From
-Collapse +Expand Delphi Store

Prestwood eMagazine

May Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...Language Det...   Print This     
  From the February 2012 Issue of Prestwood eMag
Delphi Language Details:
Using MessageBox
Posted 17 years ago on 8/21/2002
Take Away: MessageBox is similar to ShowMessage but gives you more control over how it displays. This one is a favorite of developers because it is a Windows API function wrapped in a Delphi method. This is important because many Windows development languages support the MessageBox function.


To do:

  1. Add a button to our form (this time change its Caption to MessageBox1).
  2. Double click on the button to bring up the editor.
  3. Type line 3 from the code listing between the begin and end.
  4. Run and test the program.


  1. The begin and end mark this method’s code. Notice that the end has a “;” after it.
  2. There is a main begin and end that mark the application’s code. Notice the final end has a “.” after it. (You can see this by switching back to Delphi.)
1. procedure TForm1.Button2Click(Sender: TObject);
2. begin
3.   Application.MessageBox('Hello World!', 'My First App', 0);
4. end; 


Share a thought or comment...
Comment 1 of 2
MessageBox also allows you to display multiple buttons and know which the user pressed. This is very usefull for limited yes/no type user interaction.

To do:

  1. Add a button to our form (set its Caption to MessageBox2).
  2. Double click on the button to bring up the editor.
  3. Type lines 2 and 3 from the code listing above begin.
  4. Type Lines 5 and 6 between the begin and end.
  5. Run and test the program.


  1. Notice we declared sAns to be an integer. Then assigned the return value from MessageBox to it.
  2. Because Pascal is a highly typed language, we must use methods like IntToStr to convert a value to the correct type for the given method (as in line 6).
1. procedure TForm1.Button3Click(Sender: TObject);
2. var
3.   iAns : Integer;
4. begin
5.   iAns := Application.MessageBox('Is this fun?', 'Question', MB_YESNO);
6.   ShowMessage(IntToStr(iAns));
7. end; 
Posted 17 years ago

Comment 2 of 2
the syntax is nice but u can always go direct:

MessageBox(handle, 'Check this out!, 'Box Head', MB_ICONWARNING)

That's it.


Posted 13 years ago
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1272A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100006 Counter
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site:

©1995-2019 Prestwood IT Solutions.   [Security & Privacy]