Sie sind auf Seite 1von 12

Introductory Programming using

Borland Delphi 7 Personal Edition IDE

A Bryan Miller tutorial


“transmitting ideas, from my mind to yours…”
Introductory Programming using
Borland Delphi 7 Personal Edition IDE

Introduction

You are obviously interested in learning how to write computer


programs, as evidenced by the fact that you downloaded this
document and are reading it.
My own interest began several years ago, and I have indulged that
interest via self-teaching. I have dabbled in QuickBASIC, VisualBasic
6.0, C++, and C#. My most recent interest is Borland’s Delphi, a
derivative of Pascal. Although I prefer C#’s syntax, Delphi produces
stand-alone executables. This endears it to me, because many people
seem to be opposed to C#’s requirement for the .NET Framework.
Delphi is capable of most any sort of project that you as a
programmer would care to undertake. And it has a wide array of
available components for building just about any sort of GUI (Graphical
User Interface) you might desire.

Intended Audience

This tutorial is intended for newcomers to programming, although


if you’re a relative novice who has only dabbled in a few other
languages, this could also be the tutorial for you.
We’ll be using Borland’s Delphi 7.0, Personal Edition. I obtained
my copy at the following download site, which was functional at the
time of this writing. It‘s about a 53.7 Mb download:

http://kewlshare.com/dl/e57da67cefee/Delphi7_Personal.zip.html

If the IDE (integrated development environment) is no longer


available at the above URL, perhaps you can find it elsewhere by
Googling it. You will need the following pieces of information to install:

Serial number : YH?Z-2WDEGK-S48529-3AS3


Authorization key : G5N-D95
Installing Delphi 7 Personal Edition

Find the downloaded archive on your drive:

If you have IZarc or similar archival compression software, you


may be able to simply install Delphi 7 using that program, as shown
below. Notice the “Install“ button around which I‘ve placed concentric
circles:

Or, you may have to locate the Windows installation file manually
and double-click on it. If you go this route, you‘ll need to look in the
/install/ subdirectory once you‘ve extracted the zip archive. Be sure to
maintain the folder paths when extracting:
Installing Delphi 7 Personal Edition

Once you’ve followed the steps I’ve outlined above, the Windows
installer should load:

Click “Next” and you’ll be presented with a screen prompting you


for a serial number and an authorization key. I mentioned them
earlier. Serial number : YH?Z-2WDEGK-S48529-3AS3
Authorization key : G5N-D95. Enter these accurately, click “Next”
again, and you’ll be presented with the License Agreement form. Click
the radio button indicating acceptance of the terms, and continue.
Installing Delphi 7 Personal Edition

The next form provides “Important Installation Information”. Read


through it if you’re bored. Actually, it is important, but don’t feel
compelled to read through right now. Click “Next”. The next form lets
you choose among a typical, compact and custom installation.
Choose “Typical” and proceed. On the Microsoft Office Controls form,
select for “Office XP” style controls to be installed, unless you have a
good reason for choosing otherwise.
The next form allows you to select the directory into which Delphi
7 Personal Edition will be installed. I recommend that you accept the
default. On the next form, ensure that “Save uninstallation database
to hard drive” is checked, then finish the installation.

Congratulations! Now, let’s fire up our new IDE…

Ach! It’s a scary-looking beast, especially if you’ve never before


dealt with a RAD tool (RADs are Rapid Application Development tools
that speed up the development of programs with graphical user
interfaces). But we’re going to tame it!
Take a break and grab a coke or coffee. Maybe spend some time with
your family. When we resume, we’ll write our first Delphi program.
Your First Delphi Program

And now it’s time for us to write our very first program in Delphi.
We will create a console mode application. A console application uses
a text only window for input and output. Generally, console apps
require little in the way of user input. Let’s create such an application
now.

Fire up the Delphi 7 Personal Edition IDE and create a new


application. Or, the IDE may automatically create a new Forms app:

Next you should choose Project … Remove Project. Select Unit1


(Form1) and click OK. Delphi will remove the selected unit from the
uses clause of the current project. Select "Project | View Source"
Edit your project source file. Delete all the code inside "begin" and
"end". After the uses keyword, replace the "Forms" unit with
"SysUtils". Place {$APPTYPE CONSOLE} right under the "program"
statement.

If you’ve followed the above instructions correctly, you should now


have a code-view window that looks like the picture on the next page:
Your First Delphi Program

You are now left with a very small program which looks much like
a Turbo Pascal program which, if you compile it will produce a very
small EXE. Note that a Delphi console program is not a DOS program
because it is able to call Windows API functions and also use its own
resources.
This is nothing more than a "standard" Delphi project file, the one
with the .dpr extension. The program keyword identifies this unit as a
program's main source unit. When we run a project file from the IDE,
Delphi uses the name of the Project file for the name of the EXE file
that it creates - Delphi gives the project a default name until you save
the project with a more meaningful name.
The $APPTYPE directive controls whether to generate a Win32
console or graphical UI application. The {$APPTYPE CONSOLE}
directive tells the compiler to generate a console application.
The uses keyword, as usual, lists all the units this unit uses (units
that are part of a project). As you can see, the SysUtils unit is included
by default. Another unit is included too, the System unit, though this is
hidden from us.
In between the begin ... end pair you’ll add your code that will
make the program do something useful (or at least interesting).
Your First Delphi Program

If you go ahead and build the program (Project … Build Project on the
menu), and then navigate to the project’s subdirectory within your
Delphi installation directory, you’ll see that the executable produced is
quite small -- only around 39 Kb, as opposed to over 300 Kb for even
the simplest GUI application (a program that presents a graphical user
interface, such as the ubiquitous Windows form) in Delphi .

If you try running this small program by double-clicking it, or by


right-clicking and then left-clicking “Open” or “Run As”, you might see
a momentary console window, but it simply blips onto the screen and
is quickly gone.
To get it to stay until you press the Enter key, add the ReadLn
command in between the begin and end keywords, as shown on the
next page:
Your First Delphi Program

Now re-compile and run the program again. This time the console
window appears and stays until you press the Enter key.

You can enter text into the window by typing at your keyboard.
Try it by entering your name. To cause the program to exit, and the
console window to disappear, press the Enter key. Notice that by
default the console program display, in its title bar, the full path to the
executable.
Your First Delphi Program

Now use the File…Save As command to save your project as


“barebones_console_app”. Then recompile and run your program.
Notice that the text name of the executable, as shown in the running
program’s title bar, has changed to correspond to the renamed project
name.

Another reason that I had you save the project under this name is
so that we can use it as a template, a starting point for future console
applications that we will write. It will save us the work that we had to
do initially to turn a GUI app into a console mode application.

Your project’s directory still contains the old project executable.


You can delete it. Your project directory should now look something
like this:
Your First Delphi Program

Well, we haven’t done anything impressive yet. But we have


written our first Delphi program, and that is significant. Take pride in
this small but meaningful accomplishment. As in the study of
mathematics, learning to write programs is an incremental process in
which we slowly build upon knowledge previously acquired. So be
patient, and persistent, as you follow along in these tutorials. You will
eventually find that you have moved on to bigger and better things.
In the next lesson, we will write another console mode application,
and we’ll learn a few handy tricks we can keep in our toolbox as we
prepare to write larger, more useful console applications.
The file you’ve been reading should be named
“wbm_Delphi_one.PDF”. The next tutorial that you will almost
certainly want to read is named “wbm_Delphi_two.PDF”.

Bryan Miller can be contacted at wmmiller@duo-county.com or at


bmiller@adanta.org

He maintains his church’s website at


http://www.glensforkumc.com

Das könnte Ihnen auch gefallen