Getting Started with Delphi at TU/e
Borland Delphi, from now on also shortened to Delphi,
is a set of tools for professional software development
on the MS-Windows/Intel platform.
(A Linux version,
named Kylix,
has also been available.)
Delphi has one
Integrated Development Environment (IDE)
with a graphical user interface,
which controls the project manager, editor, object browser,
compiler, linker, debugger, etc.
There is a separate command-line compiler
for use in a command window.
Delphi is based on the programming language Object Pascal,
which very much resembles the
Turbo Pascal dialect,
including its object-oriented features.
On-line documentation for Delphi is available in the following places:
- From the MS-Windows Start menu:
- Programs -> Borland Delphi 6 -> Help -> Using Delphi
- Programs -> Borland Delphi 6 -> Help -> Programming with Delphi
- Programs -> Borland Delphi 6 -> Help -> Object Pascal Reference
- From the Help menu in the Delphi IDE
(also see Starting the Delphi IDE).
The beginner, being overwhelmed by all the help,
should look under
Help -> Delphi Help -> Contents -> Object Pascal Reference,
and look no further than
- Overview
- Programs and units
- Syntactic elements
- Data types, variables, and constants
- Procedures and functions
- ...
- Standard routines and I/O
- ...
- Object Pascal Grammer
- From the Help button in dialog boxes of the IDE.
- Using function key F1.
When some word is selected in the editor, help for that word is given.
The following books are just two of many books
that explain the basics of using Delphi:
M. Stefanski.
Basiscursus Delphi 4.
Academic Service, 1999 (in Dutch).
R. Lischner.
Delphi in a Nutshell: A Desktop Quick Reference.
O'Reilly, 2000.
The Delphi command-line compiler can be invoked in a command window
for compiling a console application by
dcc32 -cc <file.pas>
assuming your execution path includes Program Files\Borland\Delphi 6\Bin
.
In this way, most Turbo Pascal programs can be compiled into executables.
Advantages of using the command-line compiler are:
- You can use your favorite editor.
- You do not have to create projects in separate folders.
- Start -> Programs -> Borland Delphi 6 -> Delphi 6
- Starts the Delphi Integrated Development Environment.
Help is available under the Help menu (also see Delphi documentation).
Experimentation is encouraged (pull down those menus :-).
Context menus are opened by `right'-clicking on items.
NOTE:
By default, Delphi starts up with a blank project for developing an
MS-Windows GUI application (usually a Form with a grid of dots is shown).
For `simple' programming tasks, this is NOT what you want.
Choose File->Close All to get rid of this blank project
(do NOT save anything).
All files needed to build a program are gathered in, what is called,
a project.
A Delphi Project File with extension .DPR defines which files
belong to a project.
It is recommended that you make a separate folder for each project.
- Double-click a Delphi project file
- Starts Delphi and opens the project.
NOTE:
Even though the project is now open,
it is possible that you do not see any windows for this project.
Also see Viewing the program in a project.
Projects can also be opened from the Delphi IDE:
- File -> Open..., or Ctrl+O, or `Open project' icon on main SpeedBar
- Select an existing Delphi Project File from the dialog box to open it.
- File -> Reopen
- Reopens a recently opened project.
You can try the project
GetalKlutser (in Dutch).
The zip archive contains one folder named `GetalKlutser' with
a Delphi Project File `GetalKlutser.dpr' and all related files
for a console application.
(Here is a `true' MS-Windows version:
NumberMunger.)
- View -> Project Manager
- Opens the Project Manager window,
which shows what other files (e.g. for units) are in the project.
`Simple' projects have no such other files.
Make sure that the project is open.
- Project -> View Source
- Opens the Project Source window,
which displays the program texts (=source)
of the various parts of the program.
Make sure that the project is open and
the program source is visible.
- File -> Print..., or Ctrl+P
- A dialog box appears to change some settings
(such as Header/page number,
Line numbers, Syntax print, Wrap lines,
and Left margin),
or to set up the printer
(such as printing on A4 paper and 2-up printing).
A left margin of at least 10 is recommended.
Make sure the project is open in the IDE.
- Run -> Run, or F9, or `Play triangle' icon on main SpeedBar
- If necessary,
the Delphi Object Pascal Compiler and Linker are invoked
to build an executable (with extension .EXE).
A progress window is shown during compilation and linking.
A Console Application
(also see Changing the options of a project)
automatically opens its own console window
(some, or even all, Delphi windows may be hidden, also see
Changing the IDE preferences).
When the program finishes, this window automatically closes
and hidden Delphi windows are shown again.
It is often convenient to include the lines
; write('Type enter to dismiss this window: ')
; readln
at the end of a console application.
Before typing enter,
you can use the Mark and Copy buttons of the window
to save program output produced in the window
(e.g. to paste it into some other
editor window where you are making a report).
- Run -> Trace Into, or F7, or `Trace Into' icon on main SpeedBar
- Run -> Step Over, or F8, or `Step Over' icon on main SpeedBar
- The first time you invoke Trace Into or Step Over (see below for
the difference),
the program's console window opens (after recompiling if necessary),
and the program stops at the very first statement.
The highlighted (blue) line in the program's source window
(also marked by an arrow in the left margin)
is the next line of code to be executed.
Each next time you invoke Trace Into or Step Over,
one line of code is executed
and after that the program is stopped again.
NOTE: It is necessary to provide input in the program's console
window when a read or readln statement is executed;
otherwise, stepping will NOT continue.
Program variables can be inspected by clicking on the variable name
in the project source window, or by adding them to the Watch List
(see Watches and Add Watch below).
They can be modified through the Evaluate/Modify window (see below).
Trace Into executes one line of the program.
When that line calls functions or procedures,
execution stops at the first line of the body of the first call.
Step Over executes one line of the program.
When that line calls functions or procedure, these are executed without
intermediate stopping.
- Run -> Program Reset, or Ctrl+F2
- Tracing will resume from the beginning of the program.
- View -> Debug Windows -> Watches
- Brings up the Watch List window,
which shows a list of user-supplied expressions (e.g. variables) and
their current values.
- Run -> Add Watch..., or Ctrl+F5
- Opens the Watch Properties window,
which can add expressions to the Watch List.
- Run -> Evaluate/Modify, or Ctrl+F7
- Opens the Evaluate/Modify window,
where expressions can be evaluated on the fly in the current state, and
where program variables can be modified.
- Run -> Run to Cursor, or F4
- Execute statements, until arriving at the line with the cursor
- View -> Debug Windows -> Call stack
- Brings up the Call Stack window,
which lists the order in which the currently active procedures and functions
have been called and what their parameter values are.
Make sure the project is open in the IDE.
- Project -> View Source
- The program text (=source) is shown in its own window by the
Delphi Editor.
The Delphi Editor is a fairly standard text editor with keyword highlighting
and some other features, such as an extensive Search/Replace commands
(see Search menu).
You can change the program text in this window.
- File -> Save, or Ctrl+S, or `Save to disk' icon on main SpeedBar
- Saves changes to disk.
There is a preference setting
(see Changing the IDE preferences)
to automatically save edited files before compiling a project.
This setting is advisable, because bad programming errors may cause your
computer to `crash' and thereby lose all unsaved changes.
When the Delphi Object Pascal Compiler or Linker
detects errors or reasons for warnings,
these are listed at the bottom of the editor window.
Double-clicking a message in the bottom part,
highlights the corresponding line in the top part.
The message briefly explains what is the matter.
Additional help can be obtained by selecting the message and typing F1.
NOTE: The `real' cause of an error may be located in
a different place from where the tools mark it (viz. earlier in the file).
When a runtime error occurs during the execution
of a console-application program
(e.g. integer overflow),
a message is shown in the program's console window.
However, when the program is run from the IDE,
the console window immediately closes afterwards,
giving you too little time to read the message.
Workaround:
Open your own command window (from the Start menu)
and execute the program there `manually' (i.e. not from the IDE)
by typing its name when in the appropriate folder.
The runtime error message then remains visible.
This is slightly complicated (but making it easier is even harder :-)
- Open the Delphi project `TUE' in the folder `TUE Console Application',
or an existing Delphi project that was derived earlier from the `TUE' project.
Also see Updates for
project `TUE' and Opening an existing project.
- Use File -> Save Project As to save this project
in another folder under another name.
You can create a new folder from the Save Project As dialog box.
To change the name, replace the TUE part of the file name
before clicking Save.
Delphi automagically changes the program name in the file as well
(next to the keyword
program
).
- The newly made copy becomes the active project.
- See Changing the program in a project
for instructions on changing the program and saving changes.
NOTE:
- A Delphi program must have the same name
(next to the keyword
program
)
as the file it is stored in.
Consequently, the file name (minus its extension)
must be a legal Pascal identifier.
If this condition is not met,
Delphi will not compile and run the program.
The project options for application projects started from
`TUE Console Application'
(see Creating a new project,
and Updates)
have been set appropriately for `beginners'.
The project options for application projects started in other ways
(e.g. the default blank project when Delphi is started from the Start menu)
are usually less appropriate and need adjustment.
You can access the project's options as follows:
- Project -> Options..., or `Option' icon on Project Manager speedbar
- The Project Options window opens.
Recommended project options are:
- Compiler
-
- Runtime errors: check `Range checking', `I/O checking', `Overflow checking'.
- Linker
-
- EXE and DLL options: check `Generate console application'
The behavior of the IDE can be modified through a large
set of Environment Options.
- Tools -> Environment Options...
- The IDE Environment Options dialog window opens.
Some recommended IDE settings are:
- Preferences:
- Autosave options: check `Editor files', `Desktop'
(Help button provides details).
- Preferences -> Debugging: check `Step program block'
- Preferences -> Compiling and Running: UNcheck `Minimize on run',
check `Hide designers on run'
- Editor:
- Check: `Use syntax highlight'
© 2001-2002,2004, Tom Verhoeff
(TU/e,
Faculteit Wiskunde en Informatica)
Feedback about this page is welcome