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

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

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

   ► KBProgrammingDelphi for W...Language Basics   Print This     
 
Delphi Language Basics:
20 Minute Delphi Primer: Displaying Things
 
Posted 16 years ago on 2/26/2008 and updated 10/24/2009
Take Away:

This primer is intended for those just getting started in Delphi and focuses on displaying things.

KB100883

Displaying Things in Delphi

One of the easiest ways to learn a language is to jump right in and make it do things. You can take this tutierial right on-line. Just task switch beween your browser and Delphi. In this tutorial, you will create a form with several buttons on it. Each button will demonstrate a technique for displaying information to the user. Lets get started by doing the following to do steps.

To do:

  1. Start Delphi

Note We strongly recommend that you type in and run each exercise. Just reading about something isn't nearly as good as doing it.

1. Using ShowMessage

ShowMessage displays a simple dialog box with the text you provide it. It is one of the most used ways of displaying information.

To do:

  1. Create a new application by selecting File | New Application.
  2. Place a button on the form and change its Caption property to ShowMessage.
  3. Double click on the button to bring up the editor.
  4. Type line 3 from the code listing (on the right) between the begin and end.
  5. Run and test the program by selecting the Run VCR style button (looks like a play button).

Notes

  1. The user has no way to modify the text.
  2. Notice the semi-colon at the end of the line you typed in.
  3. If you have trouble compiling, try the copy/paste method to typing.

Code Listing

procedure TForm1.Button1Click(Sender: TObject); 
begin 
	ShowMessage('Hello World!'); 
end; 

2. Using MessageBox - Part I

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.

Notes:

  1. The begin and end mark this methods code. Notice that the end has a ; after it.
  2. There is a main begin and end that mark the applications code. Notice the final end has a . after it. (You can see this by switching back to Delphi.)

Code Listing

procedure TForm1.Button2Click(Sender: TObject);
begin
    Application.MessageBox('Hello World!', 'My First App', 0);
end;

3. Using MessageBox - Part II

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.

Notes:

  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).

Code Listing

procedure TForm1.Button3Click(Sender: TObject); 
	var 	
iAns : Integer; 
begin 	
	iAns := Application.MessageBox('Is this fun?', 'Question', MB_YESNO); 	
	ShowMessage(IntToStr(iAns)); 
end; 

4. Using InputBox

InputBox allows you to set a value, display it to the user, and have the user change it. Although InputBox generally isnt flashy enough for finished applications, it is great for debugging and smaller in-house applications.

To do:

  1. Add a button to our form (set its Caption to InputBox).
  2. Double click on the button to bring up the editor.
  3. Add lines 2, 3, 5, and 6 from the code listing to it.
  4. Run and test the program.

Notes:

  1. Notice we used to the + symbol to concatenate two strings (a literal and a variable).
  2. Because themethod Button4Click belongs to the class TForm1, the first line must include both to uniquely identify the method. Youll learn a lot more about object oriented programming as you learn Delphi. For now, this simple definition will work.

Code Listing

procedure TForm1.Button4Click(Sender: TObject);
var 	
	sAns : String; 
begin 	
	sAns := InputBox('Question', 'What is your name?', 'Tiger Woods'); 	
	ShowMessage('Hello ' + sAns); 
end; 

5. Using the StatusBar Component

The StatusBar component allows you to write text to the status bar. This is one of the most common ways to display information to a user without stopping their work.

To do:

  1. Add a StatusBar component from the Win95 tab to the form.
  2. Change the SimplePanel property of the StatusBar to True.
  3. Add a button to our form (set its Caption to StatusBar).
  4. Add lines 2 and 3 from the code listing to the Click event of the button.
  5. Run and test the program.

Notes:

  1. Notice we used two apostrophies in a row to represent one apostrophe in a literal string.
  2. Notice the use of dot notation in line 3 to set a property of an object.

Code Listing

procedure TForm1.Button3Click(Sender: TObject); 
begin 	
	StatusBar1.SimpleText := 'Isn''t this cool!'; 
end;

Comments

1 Comments.
Share a thought or comment...
First Comment
Comment 1 of 19

I need to run 3 find out and need more information   

Posted 55 months ago

Comment 2 of 19

Look https://rankmywriter.com/customwritings-com-review and check writers you want to get essay) it is the best way to ptotect yourself

Posted 55 months ago

Comment 3 of 19

Wow you have made some nice information provide I really like this stuff I really enjoyed this blog I want to appreciate this article  Mens leather jacket

Posted 55 months ago

Comment 4 of 19

This is the first time that I visit here. I found so many exciting matters in this particular blog, One thing I would like to request you that pls keep posting such type of informative blog. Movie Jackets

Posted 55 months ago

Comment 5 of 19

I appreciate this blog your blog is vert help full for me i really enjoyed this stuff dude. James Bond Suit

Posted 55 months ago

Comment 6 of 19

It is the best way to deal with manage a wide scope of creating assignments for college or school. In a manner of speaking, it‘s Finance Homework help gave by the writers and editors at a sensible and modest expense. Our writers completely appreciate the truth of this issue. Moreover, every piece, article or research paper outfits an ordered reference list with all the significant composing resources.

Posted 54 months ago

Comment 7 of 19

Hand-off pleased yo see your post on the web, I value you writing this post and furthermore the remainder of the website is great. I should need to express profound gratitude for sharing this post. Captain America Jackets

Posted 54 months ago

Comment 8 of 19

Good post. Thank you for sharing this with us.
party poison jacket

Posted 52 months ago

Comment 9 of 19

Good post i really like your content thanks for share us Cyberpunk 2077 Cosplay

Posted 47 months ago

Comment 10 of 19

I really enjoyed reading your blog it is very helpful.  Moretti Longmire Jacket

Posted 42 months ago

Comment 11 of 19

Wonderful article. It‘s very useful. As a maths tuition service provider, I really appreciate your post. Thanks for sharing this with us.I find a very good website for the maths tuition, You can visit this site.

Posted 42 months ago

Comment 12 of 19

I think this is the best blog for me because I am a marketer and now I have joined Dissertation Help recently and also have decided to work with it because the academic papers is the best one for those students who want to get writing skills for the completion of their thesis and assignments.

Posted 42 months ago

Comment 13 of 19

Math has always been a tough subject for many, not only maths but in case of all the subjects, not all the students are able to understand the lecture that has been provided by the professor, so they face problem in writing the assignments. I myself is an example of such a situation so I take help from my paper writer to complete my assignments. It not only helps me to score well but make me understand in a good way.laughing

Posted 42 months ago

Comment 14 of 19

Tremendous article. It‘s very useful. As a maths lessons provider company, I really respect your submit. Thanks for sharing this with us. I discover a very good internet site for Animated 2021 Paw Patrol Movie Vest, you can go to this website.

Posted 36 months ago

Comment 15 of 19

The submit could be very informative many humans need to look at this shape of the publish I‘m additionally part of them and after analyzing always deliver genuine evaluations but, Nick Fury Secret Invasion 2022 Samuel L Jackson Brown Coat this is not my profession I‘m a fashion clothier and also designed the and after the process.

Posted 31 months ago

Comment 16 of 19

I came to your net web page the day past and I have been analyzing it on a regular basis. Mens Black Leather Jackets for Sale you have quite a few excellent pieces of info on the site and I really like the style of your website at the same time. Keep up the best work!

Posted 30 months ago

Comment 17 of 19

When setting goals, use the SMART criteria: Specific, Measurable, Achievable, Relevant, and Time-bound. This framework can help you create clear and attainable objectives in various aspects of life. Sky High 2023 Rosa Red Puffer Jacket

Posted 14 months ago

Comment 18 of 19

This topic on time management has been a lifesaver for me. The practical techniques and time-saving hacks shared here have transformed how I approach my daily tasks and responsibilities. Vin Diesel Jacket Triple X I feel more productive and in control of my schedule than ever before. Thank you for sharing such valuable insights!

Posted 8 months ago

Latest Comment
Comment 19 of 19

This article has been really useful. I value your generosity in making it available to me and the public at large. fnaf unblocked

 
Posted 8 months 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 = P1116A1
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 play-drums.com 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 #100883 Counter
9773
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


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