Home
Intro
LC
ACR
About

Day 10 - Introduction to Delphi

-=-=-=-=-=-=-=-=-=-=-

What you are going to learn today:

  • What is Borland Delphi
  • How do you use Delphi
  • And how we are going exploit it

-=-=-=-=-=-=-=-=-=-=-

You're not in the '90s if you don't know Windows - and the latest rage in programming are the Rapid Application Development (RAD) systems. RAD is just a term used to describe programming systems which make programming fast, easy, and efficient, and as you'll see later, this is totally true.

Delphi? Wealthy? Healthy?

Those of you who program in Windows may have heard of VB, the (in)famous RAD development system for Windows created by Microsoft. Although easy to use, VB has the following weaknesses:
  1. VB programs are slow.
  2. VB's interface is non-productive
  3. VB does not allow you much flexibility
  4. VB uses BASIC as its core language
  5. VB is by Microsoft
Delphi, on the other hand, is the exact opposite of all those points. Delphi, like VB, allows you to 'draw' your windows on your screen, then add code as you need it. Hmmm, very interesting...
    Stop! - Ahhh, before you start thinking that Windows programming is the easiest thing in the world, I would like to tell you a story of my first real experience programming in Windows. It was a few years back, when I had just got a copy of Turbo C++ for Windows. I thought I could just type a few lines and make a great program, but believe it or not, even till today, I still can't make a functional Windows program with that package. So, thank your lucky stars that somebody thought of intelligent programs like Delphi. Just imagine typing hounds of code for one simple file dialog box!
Essentially, there are two versions of Delphi: Delphi 1.0 and Delphi 2.0. But wait! This is just in - there's a Delphi 3.0! Essentially, Delphi 1.0 is for 16-bit development while Delphi 2.0 and 3.0 are for 32-bit development. Delphi 3.0 has features for developing ActiveX (just some more fun stuff from Microsoft), but because it's just too recent, we can't cover it in these tutorials.

How do we use Delphi?

This is where you draw First thing you must learn about Delphi programming - the process goes Draw, Change, Code. First, 'draw' your program on the screen, change what you've just 'drawn', then write code to accompany the program. To 'draw', you must first locate the big blank window on your screen which looks as if it had 'a bad case of measles'. (That line was lifted from Delphi Programming for Dummies!) This is where you start drawing your programs - select the button with the big 'A' on the top of the screen and drag across the 'canvas'. Instantly, a giant label appears on the screen, with the text: 'Label1'. Get the idea? Flip to the other tabs and see what other things you can 'draw'. Some things, however, don't show up on the screen. They just remain a small icon stuck there with super-glue or something. Like any other painting tool, you can remove these items by selecting it and pressing Delete.

Set properties here Now that you've drawn something, you might want to change their properties. For instance, you might want this Label to be blue. Simple, just use the Object Inspector to change it. In a sense, you're changing what you've just 'drawn'. Isn't that great? Much better than your old Crayola crayons.
To change an object property, you look it up on the Object Inspector, then change its value on the right. For instance, to change the text on the label, you can change its 'Caption' value to 'Delphi!' Some properties, you may also notice, have a '+' sign right before its name. This means that that property can be expanded by double clicking on its name - for instance, you can double-click on 'Font' and change its 'Color'. You'll see a pull-down list with all the possible values you can use to define its colour. Change it to clBlue for instance, or clGreen. You'll see that the colour of the text changes accordingly. Now you're getting the idea! Play around - All great fun! You're playing with colours, right? You can also double double click on the value to bring up a colour selection box. Ooo, ahhh...

Edit your code with the Code Editor

Enough. Now that you have customised what you have 'drawn', the next step is to add code to each object. Look back at your Object Inspector. Notice that you've only been looking at the 'Properties' tab, the one you used to change your 'drawing'? Click on the second tab 'Events', and voila! You see the list of events linked to the object that is currently selected. See, the 'OnClick' event is activated when the object currently selected is clicked. Considering that you haven't done anything stupid, the following steps would create a 'Hello World!' application.

  1. Click on the form, and go to the Object Inspector
  2. Click on the Events tab
  3. In the OnClick event, you can either type your own procedure name in the value column or just double-click to let Delphi handle the naming complications (We highly recommend the second option!)
  4. Instantly, the Code Editor comes out for you to edit your code. Notice I said 'edit'? Well, that's because there's already code in your window! Believe it or not, Delphi created all that for you...
  5. Type the following code between the 'begin' and 'end' blocks:
      Form1.Caption := 'Hello World!';
    
  6. Click on the green 'Play' button at the top of your screen

(Object Name) Form1.Caption (Object Member)

Wait for a moment as your hard disk lights flash... Poof! Instantly, a great window appears on your screen, beckoning you to click on it. Do so. At once, the title bar changes to say 'Hello World!' It works! Your first Delphi program works! Let's look at your code: First of all, as your code was for the form's OnClick event, your code would only be executed when the form gets clicked. When it does, it sets the Caption member of Form1, which is the form, to become 'Hello World!' Huh? Well, look at it this way. The form is actually a record, and you're setting the Caption property to become what you want it to be. (And as you'll see later, the form is not only a record, it's an object!) Just treat the form as a record for the moment and you'll be okay.

Exploitation Time!

Now that you've had a taste of Delphi, it's time to tell you of our devious plans... We plan to use Delphi to teach all of you the concepts of Windows and Object Orientated Programming, the two main topics of Class A. What? You don't have Delphi? Well, get it! Better now than never. Let's give you our top 10 reasons why you should get Delphi now:
  1. We're all going to use Delphi in the future, anyway.
  2. Delphi has all the source code you could ever want in a development system.
  3. Delphi can get you results - fast!
  4. Wait a minute! Delphi was fast in the first place!
  5. Pascal is my sort of language, right?
  6. Delphi comes with a fantastic Visual Component Library (VCL) which, em, never mind...
  7. Delphi was a holy city in ancient Greece.
  8. We all love Anders Hejlsberg!
  9. Delphi is the love of the entire nation!
  10. Borland Delphi is not Microsoft Delphi!
Now, wasn't that persuasive? Choke out your money, if you can, and go get your copy of Delphi at your nearest dealer! (Em, I'm still wondering who's the dealer for our area. Hmmm...) Whatever it is, just get it! Period.

End Of Day 10

As you can see, Delphi is very different from the console Turbo Pascal you've been learning so far. Who knows, you just might give up Turbo Pascal programming altogether! Some of you may be puzzled though. Why is it that Delphi executes code only when an event occurs? Well, you'll find out in Day 11! So good luck!

-=-=-=-=-=-=-=-=-=-=-

HomeIntroLCACRAbout
Back to Class A

-=-=-=-=-=-=-=-=-=-=-

This page is ThinkQuest entry 11127.
email: tq97-11127@advanced.org