



|
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:
- VB programs are slow.
- VB's interface is non-productive
- VB does not allow you much flexibility
- VB uses BASIC as its core language
- 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...
- 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?
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.
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...
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.
- Click on the form, and go to the Object Inspector
- Click on the Events tab
- 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!)
- 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...
- Type the following code between the 'begin' and 'end' blocks:
Form1.Caption := 'Hello World!';
- Click on the green 'Play' button at the top of your screen
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:
- We're all going to use Delphi in the future, anyway.
- Delphi has all the source code you could ever want in a development system.
- Delphi can get you results - fast!
- Wait a minute! Delphi was fast in the first place!
- Pascal is my sort of language, right?
- Delphi comes with a fantastic Visual Component Library (VCL) which, em, never
mind...
- Delphi was a holy city in ancient Greece.
- We all love Anders Hejlsberg!
- Delphi is the love of the entire nation!
- 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!
    
This page is ThinkQuest entry 11127.
email: tq97-11127@advanced.org
|