HOME
- - - - - - - - - - - - Other material for programmers
Delphi and Pascal Programming Tutorials
First: Apologies: For a time (up to 15 June 08) many (still some?) pages of this and related sites were being "hi-jacked". Are any others still afflicted? Please let me know?)
Looking for write-ups of how to do specific
things in Delphi or Pascal? You've got the right site! Feel free to use these tutorials in programming courses, but a credit of the source would be appreciated. Speaking of which... the following was a great help to my own programming: 'Borland Delphi How-To', from the Waite Group, by Frerking, Wallace and Niddery, ISBN 1-57169-019-0. Its approach suited my needs, and helped inspire the form of these tutorials: Most are self-contained explanations of how to accomplish a specific task, or use a particular component of the language.
First catch your Delphi! Obtaining a copy of Delphi is not as easy as it once was, but you can still do it, and it is worth the trouble.
There are more notes at the bottom of the page about other offerings, my editorial philosophy, a button to email me, and a search engine to help you find things in my site.
For a bit of fun, see my demonstration of Writing Delphi- like applications with nothing more than Open Office!
Forgive a little impertinence? You came here, I hope, for Delphi Tutorials. Just before you go on to them, I invite you to consider some pages I've produced in an attempt to persuade you that the database being shipped with Open Office version 2, called "Base", or "ooBase", is worthy of your consideration.
See Also: Delphi Course:
Further to my longstanding Delphi tutorials (Table of Contents follows), I have started a series of essays which will help you become a good Delphi programmer if you take the time to work your way through them. The Tutorials can be tackled in whatever sequence suits you. The essays of the Delphi course are, in the main, meant to be read in sequence. Delphi Course Table of Contents
Table of Contents, Delphi and Pascal
Tutorials:
Delphi.....
Level Zero:
Pascal course: If you are not only new to Delphi, but also new to programming, you might want to study Pascal a little first! There is a free product, Pascalite, which you could use for that. What you learn with it will all contribute to getting going easily with Delphi. Working with Pascal first lets you master one group of issues (which will matter in Delphi programming, too) before you contend with them AND some issues that are involved with any Windows language. The page about my course also tells you how (6/2007) to obtain the excellent Borland Turbo Pascal, too, which will suit some needs.
Want a bit of fun? If you have the excellent, free, Open Office installed on your Windows or Linux machine, you can write applications similar to many of the applications in this tutorial! I've produced a little demo, consisting of a single "document" for Open Office's wordprocessor, ooWrite. If you have Open Office on your machine, and download my demonstration, you will see a "page" of "wordprocessor" material with a button, an edit box, two spin boxes, and some labels, for output. You will see text manipulation, message boxes, and arithmetic. Almost like something created with Delphi! Fun! (The details of how the controls were made "live" are also given.)(The demo was written for OO version 2. I believe the same things were possible in version 1.)
Level 1 Tutorials:
(At the moment, there is also some Level 1 stuff in the Level 2 tutorial called 'Adding things to a unit')
Start Here This takes a complete beginner
through a first project, covers points that apply to any project, and
covers some points about conventions used in the other tutorials.
The Whole Picture An overview of the parts of any Delphi project.
This is more 'philosophical', less 'how to', than most of my tutorials.
Subroutines: Procedures and Functions. Essential building blocks. This is an important tutorial, and written in May 2007, when I am past making some of the mistakes present in earlier tutorials!
Making it work: Tips and advice on debugging.
Also more 'philosophical', less 'how to', than most of my tutorials. (See also the Pascal debugging information in the Pascal section below.)
Level 2 Tutorials:
How to..... Make a 'beep' or other noise.
How to..... Blank the monitor by turning it off.
How to..... React to user's mouse actions.
Keeping the customer satisfied... How your program can determine your user's wishes (Pt 1. See also Pt 2, in level 3). This tutorial comes "recommended": check it out, please, even if determining user's wishes wasn't the main thing you were looking for?
Menu, "About" page and Quit option in menu... How to add them to a project.
File Handling... How to read data from files on disc, and write to such files. (A long tutorial)
Re-using a project... A short guide to building a new project from an earlier, similar, one.
Adding Things To A Unit... Where put things. Things that matter. Matters of scope.
This tutorial is full of Good Stuff... but very untidy, badly organized at the moment. I will try to sort it out, but for now: You have been warned!
Syntax Notation... how to read important stuff.
You will learn more from the Borland "Help" files once you master the information in this tutorial.
State Diagrams... I recommend you read this short general note on using state diagrams. They help you keep a clear idea of what you're trying to create. Flowcharts are good for small "corners" of your project, but since Windows (and Linux) are event driven, flowcharts are limited in their usefulness for managing the overall picture.
A Complete Example... This was written in May 2007, and is more polished than some of these tutorials. It gets off to a slow start, but once it is underway, it takes you quite quickly through the creation of something bigger than a typical Level Two application. What it does is not the main point... The main point is how the application was built, from empty form, thought stages, to finished creation. The application manipulates character strings.
Command Line Parameters... PLEASE have a look at this... it is quite short. You will be shown a way to achieve some of the benefits of .ini files and the registry... without presuming to write things onto your customer's systems.
Using the TTimer component... This not only gets you started with using an important component, but it should also help you extend your skills for working with Windows' fundamental event driven nature.This tutorial was heavily edited 5/07 and a) is polished and b) covers some essential aspects of writing Delphi programs. It isn't easy or short, but it is highly recommended if you are willing to make an effort to make progress! It isn't just about the Timer component.
An example- Reading Skill Exerciser... This comes with complete sourcecode for you to peruse. It illustrates using the OnChange event of an edit box to respond to user input. It also uses a timer to display a list of words on the screen for a time-limited reading opportunity. The use of simple Try... Except blocks is also shown, in the handling of an EConvertError exception.
Principles of programming, and Scrollbars, GetTickCount, etc... This also comes with complete sourcecode for you to peruse. It shows ScrollBars in action, but it also "digresses" to cover a number of general points like nesting procedure (or function) declarations, using TabOrder, and setting up enables. The useful GetTickCount gets a mention, too.
Use the events, Luke... This tutorial started as an introduction to string grids, and it does introduce them. However, while I was working on it, I "discovered" more than I'd known about using an event driven operating system. The tutorial also illustrates well good incremental development. Recommended to everyone, not just those looking for help with string grids. Not terribly long. It also leads on to an even more important Level 3 tutorial.
Level 3 Tutorials:
Quite a few of the things assigned to this level are not complex, but they were put here anyway as they were not essential to Delphi programming in general. Some others are also pretty simple, but come without much supporting tutorial material.
* * I commend this one to you... not only for the information on multiple forms, clever use of events to drive state changes, and information on passing controls to parameters, but also because is was written long after most of the material in the site, and covers general points that should help you do a better job of writing applications. (Published 9/06).
Keeping the customer satisfied... How your program can determine your user's wishes (Pt 2. See also Pt 1, in level 2).
Help Files... making the link between them and your program. (A short tutorial)
Creating an array of Edit Boxes... the
tricks explained here would work with other components, too.
Creating something to be used by many programs... Shows you how to re-use code. Write something once, use it in many applications. The tutorial does not take you all the way to registering a component so that it becomes part of the Delphi Component Palette, but it does show you how to create something which can optimize the development of a number of programs which all need a common element, for example a message box with copyright and version information. There is another tutorial on this important topic in Level Four, where some extra features provided by Delphi are utilized.
Alternate "creating something to be used by many programs"... ^^ See also previous tutorial ^^. This "alternate" is an old tutorial, not as well presented as newer (post about 1/04) ones. It does, however, describe creating a High Score Table. Try to ignore the "to be used by many programs" elements... they are better explained in the previous tutorial, but if a High Scores table is what you need, this is your tutorial!
A start on a typing tutor game... Unfinished at present. Illustrates development of an application.
How to access database files... It is remarkably easy to write a program in Delphi which allows you to view and edit files shared with Paradox, dBase, Access, etc. Learn how here!
Playing .WAV files with MediaPlayer... Whether you want your program to SAY "You have new mail...", or just need a superior "Zapp!" sound, here's how. And what you learn here probably works for playing other media, too.
Reading the joystick... doing it in Delphi 2 and above. Revised and expanded May 04. A stopwatch program is created as an illustration. See also the level 4 joystick tutorial. Sourcecode supplied.
A control program dissected... A program with checkboxes and boolean variables working together is analyzed. Downloadable sourcecode supplied.
Using DLLs. Introduction... How to use functions and procedures from someone else's dynamic link library (DLL). One is provided. There is also an optional second section about how to write your own DLL. The tutorial comes with sourcecode, and a pre-written DLL for you to use while you learn. See also my level 4 tutorial if you want more on DLLs.
Printing- a line at a time... this tutorial shows you how to send text to a printer a line at a time. There are no complex concepts, but the need isn't universal, and the help is minimal.-->
A Word Search Program... You won't need the program, but maybe some of the techniques used to complete it will be of interest! Sourcecode and .exe provided. Little hand-holding regarding how to make Delphi work, just comments on and in the finished product.
Pick a cell, any cell... Ostensibly, this tutorial is about using code to select a cell of a string grid at run time. Along the way, some more generally important material arises concerning using references to Delphi created objects, e.g. the object in "sender" arising from Delphi created event handlers.
---------
Drawing or viewing pictures/ graphics, ETCETERA: Just to help you find things, I'm grouping (*) the following Level Three tutorials together. While a part of each of these is about drawing pictures, doing graphics with Delphi, almost all of them cover other topics, points, issues along the way....
* Introduction to Graphics... MoveTo(100,10);DrawTo(300,300); seems simple enough... but it isn't enough to make a line which will still be there after you minimize then restore the window. This tells you how to create persistent graphics, and talks briefly of loading bitmaps.
* Another drawing tutorial, with extra bits!... This is one of my more carefully done tutorials. It was completed in May 2007 when I'd been writing them for some time. It extends the work done in the previous tutorial ("Introduction to Graphics") and also shows you a bit about building easily altered programs. The graphic generated is just a bit of pretty fun poking fun at the people who thought the DRM access code could be kept a secret. There's also a bit about different number bases. ("Hex", etc.)
* Images and File Access... Display .bmp images on your form. Access all the files in a given folder on your disc, using that as the basis for a "Can you recognize..." exercise. Tutorial has rough edges, but full source listing of working program
given. (Delphi versions 4 and 7, at least, allow you to display jpegs. I don't know which version of Delphi came with this functionality... email me if you do know?... and I'm looking for a freeware component with sourcecode (or from a reputable source, like sourceforge or Tucows) for a component to allow showing jpegs in Delphi 2 applications... again, please email if you can help? A related thought: Delphi 4 (standard) can be installed on a PC with only the serial number and authorization code. You don't need "permission" from a Borland (or other corporate... e.g. Microsoft(!)) server. Do you really think that Mr. Gate's corporation is going to let you play forever with all the tools they've released "free" recently? (pre-5/07) And will other corporations always be there to re-enable things that you move to new PCs? Give me products that I can install web-less, every time!
* Graphs for mathematics... This comes with sourcecode and a compiled exe. It is a longer- than- usual tutorial because you are taken through the development of an actual, useful application. There are no particularly difficult concepts involved, apart, maybe, from the use of one subroutine to provide the OnChange handler for several edit boxes.
To write a screensaver:A screensaver is not very different from any other Windows application. Mark R Johnson has prepared an excellent discussion in the same style as my tutorials, and I see no reason to re-invent that wheel. (He's even made the source code available.) I've put this in Level Three because of some tedious odds and ends that you must address. What you have your screensaver do can be very simple.
If, by the way, you are just looking for a screensaver generating program, to display your photos, I've done a comparative review of some things... many free.. that may be of interest.
A favor, please? If you know of a good Windows screensaver which satisfies the following, please let me know? (I only need the .exe, not the source code.)
Shareware, registration less than $20.
Displays rotating cube.
Pictures on face of cube user-defined... hopefully by
some VERY SIMPLE means. Best of all: Screensaver just
uses the six images in a known location. In my perfect
world, changing the contents of one of the files would
change the image on the cube. I don't mind being
restricted to fixed image file names.
Editor's email address. Suggestions welcomed!
My thanks to the kind reader who pointed me to Xara's rotating cube screensaver. It has been running on my machine for a few months now with no problems. It even meets my "Change display by changing file contents" requirement, I think. It shades the faces as they turn... an essential "frill" to achieve best effect, I believe. Info and program at Xara's site.
Level 4 Tutorials:
Customizing a standard control... Complete
the Level 3 tutorial 'Creating an array of Edit Boxes' before
attempting this one.
File Modification... Not complex, but presented assuming some fluency on part of pupil. Replaces a file with a modified version of itself. Backs up original file.
A worked example... A program for decoding simple substitution codes. This builds on the previous tutorial.
Navigating backing store... Re-creates parts of the Windows Explorer. Also illustrates multiple windows. Uses filelistbox, directorylistbox and drivecombobox.
Using units... This was written in May 2007, so has some advantages over older tutorials. It does tackle a fairly complex topic, but a very useful one: Putting subroutines in units which can be used and re-used. In this tutorial, we go farther than we did in the earlier one on the same topic. Commended... if you are feeling up for a challenge!
Color Graphics. Dynamic resizing... How to draw in the color of your choice. How to make things on your form change size if the window's size is changed.
HTML generator... the beginnings of a program to generate online photo albums.
Angle display... a small circle with an arrow in it. The arrow can point any one of 16 directions. Originally developed to show the direction a wind vane was pointing. No "crucial" skills in this tutorial... but it is a good one, with some nice bits of elegance in the coding. Some intermediate event handler techniques illustrated. It also illustrates a use of the tag property.
Another worked example... This is bigger and moves along faster than some of my tutorials. It shows how I extracted data for a given day from a bunch of files, each holding records for many days.
Windows messages, joysticks and a stopwatch... This covers several topics, including responding to messages generated elsewhere within the computer, messages from a Windows API. There's a simpler way to read joysticks explained in a Level 3 tutorial. It comes with sourcecode.
Accessing Port Hardware... this tutorial tells you about a freeware DLL for sending messages to and from your PC via the parallel or serial port. The tutorial includes help on how to use it. You could drive electronics of your own devising attached to your PC. If you are new to DLLs, there is a Level 3 tutorial on DLLs for you. If attaching your own electronics sounds interesting, visit my page on using your computer's ports.
Using the serial port... to send message from one PC to another.
How to ensure that... only one instance of an application runs at any given time. Uses mutex.
External units... an easy way to recycle code you have written without the overheads of custom components.
DDE Client... A limited introduction to collecting data from a DDE server, using a 1-Wire/ MicroLan example.
Level 5 Tutorials:
Sit at my elbow... while I write a program that is bigger than a typical Tutorial program. Sourcecode available for download. Illustrates the development sequence. Illustrates some file handling and graphics programming.
Temperature logger... Logging and graphing data from temperature (and humidity) sensors. Comes with sourcecode. Tutorial also covers fetching XML from a webserver, as it was written in connection with the Poseidon SNMP / XML LAN / internet "thermometer" (from HW group), but it can be revised to read from other sensors. (Delphi 2, plus a free 3rd party component, ICS. This is client/ server work.)
RS-232 comms (serial i/o)... A start on a home-brew simple Hyperterminal. Can send only, so far, but doesn't require any third party components. (Delphi 2)
RS-232 comms (serial i/o) for data log devices... A simple Hyperterminal-like terminal program, configured to interact with either of two data collection devices (Anderson TM#128 / WeatherDuck). It could be adapted for other environments. The program has some flaws, but "works". Uses the freeware, with sourcecode, component TComPost from Dirk Claessens. (Delphi 2)
Differential Thermostat...A pretty "rough" "tutorial", as I suspect a limited audience... but may be useful to some! Comes with sourcecode. See Temperature Logger, above, for how to fetch XML from a webserver... the code in that is better. Written in connection with the Poseidon SNMP / XML LAN / internet "thermometer" (from HW group), but it can be revised to read from other sensors. Uses SNMP to turn on / off an output on a LAN attached device. (Delphi 2)
-------------------
My tutorials about programming for the Dallas Semiconductor 1-Wire (tm) chips, as used on a MicroLan (tm), have been moved to here.. I also maintain pages which introduce MicroLan and explain the hardware.
-------------------
Pascal
.......
(If you are interested in links to
others' work, bookmark this page so you can get back to it, and visit
my page with links. Of
course, almost everything that anyone ever wanted to know is already
on the web in Prof. Salmi's superb FAQs.... if you can find them!!! I did a link check in May 07, and, at the moment of the check, they weren't at the URL in the links below, but these wonderful resources are worth seeking out. Google should be able to help. Download
his zipped FAQ (also
available here
), unzip it, look in TSFAQP.IDX for the FAQ's table of contents.
Don't know how to unzip? Time to learn! Alternatively, use newsgroups, via
Google's Groups to obtain an answer to your question.)
Pascal Tutorials:
Pascal for those who know Basic... Some notes from me for those who know Basic, and who haven't done much Pascal.
Making it work... Help with debugging.. and on preventing the need for it.. Also useful to Delphi programmers.
Editorial Philosophy
I dislike 'fancy' websites with more concern for a flashy
appearance than for good content. For a pretty picture, I can go to
an art gallery. Of course, an attractive site WITH content deserves
praise... as long as that pretty face doesn't cost download time. In
any case....
I am trying to present this material in a format which makes it
easy for you to USE it. There are two aspects to that: The way it is
split up, and the way it is posted.
The way it is split up...
I have tried to split it up into 'bite-sized' pieces, and to
indicate which pieces are basic and of general importance, and which
address more specific issues which also happen to be complex, or
require understanding of more fundamental issues. In other words, I
try to show you how to walk before worrying about running. The 'Level
1' tutorials cover the basics. If you have no experience, start with
the level one tutorials. If you decide to jump in at a more advanced
level, and things are not clear, it might be an idea to skim the
level one topics if only to learn about my way of expressing the
concepts. See also, below, the 'difference' between Delphi and Pascal.
The way it is posted...
This archive of tutorials stretches back some way towards the dawn of the internet. Now, most of us have HTML capable wordprocessors, and newer tutorials make more use of HTML code than older ones. Is this a problem? You could save the pages from a browser, and re-load them to the browser from your hard-disc later, off-line. OpenOffice (the excellent, FREE, office suite for Windows AND Linux from www.openoffice.org) takes HTML in its stride. With WordPerfect, you can load the .htm file, select all, copy to clipboard, start a new WordPerfect document, then paste in the text, mostly intact and cleansed of HTML.
You should be able to read the tutorials on-line without
difficulty. However, you should ALSO find it easy to capture them for
off line use, including editing for your own purposes. The following
should work. I would suggest that you create a folder for the
tutorials so that you can retain my filenames with no risk of
clashes:
On-line, use your browser to view the tutorial you want to
capture.
Use the browser's File|Save As... to save the web-page to your disc. At this
point you can log off, or visit other pages, perhaps saving them,
too.
When you have logged off, just use your browser's File ! Load command to view the material. If you want to edit the files, try using your usual wordprocessor. Failing that, start Notepad (or Wordpad, or anything
you like, but then you're on your own <g>). Load the file you
saved. Turn word-wrap on. (Notepad: Edit|Word-wrap.)
Snip off the html header and footer. Re-save the document, changing the extension to .txt or .doc Depending on the tutorial, there will be more or less HTML code within the body of the text. With luck, your wordprocessor will cope with this. Give OpenOffice a try if not! Otherwise you can use global search and replaces to remove most of the tags fairly quickly.
________
This would seem to be the place for a plug for Textpad. It is much more than Notepad, while not being all that a "wordprocessor" is... but it DOES have features that you will soon come to love, if you do much work with text files.... especially programming or HTML coding. All of my web pages are created with it, and much of the other text work I do is done with it, too. It has a spell check. It has syntax highlighting. I turn to my wordprocessors (Ami Pro, for legacy work, and OpenOffice Writer for new work) only when I want to produce a letter- formatting and font options are not extensively supported in TextPad. However, it does have many, many, very neat touches which make it a joy to use for many things. I particularly like their answer to "autotext", and the fact that the user can configure how it displays different classes of documents. Here is a link to their site. Shareware: YOu can try it for free, and it is not expensive to register for continued use.
________
Filenames: I've tried to be organized: Names start Pt or Dt for
Pascal/ Delphi Tutorial. Next is a digit, for the level, then I've
used letters one after the other, e.g. Dt1a, Dt1b, Dt1c. The letter
doesn't mean much... it just shows when I got around to that
particular topic! DST files are some of those relating to the Dallas
MicroLan.
The difference between Delphi and Pascal... and the promise of Kylix....
Delphi is based on Pascal. It is for writing programs for Windows,
using Pascal.. with a lot of enhancements from those wonderful people
at Borland. If you are very new to programming, you might make
progress faster if you start with a non-Windows Pascal... there are
free ones around, details of one can be found in my free Pascal tutorials, which I would commend to Delphi users with little experience with Pascal.
In the Delphi tutorials here, you should find all you need for
Delphi programming. However, even if you never intend to program for
anything other than Windows, if you are new to programming, looking
at some of the low level Pascal tutorials might help you to grasp
important ideas for your Delphi work.
(This note added May 2007) Kylix is a product Borland brought out years ago. I've never "played" with it, but it is, I believe, a "Delphi for Linux". You take something written in Delphi (or write something from scratch, using the same skills), run it through the Kylix compiler, and, Hey! Presto!... You get an application to run under Linux. I hope that is true, and I hope Kylix hasn't "died", as I feel myself moving ever closer to using Linux.
Site Map
What's New
Search
The search engine is not intelligent. It merely seeks the words you specify. It will not do anything sensible with "What does the 'could not compile' error mean?" It will just return references to pages with "what", "does", "could", "not".... etc.
In addition to the tutorials for which this page serves as Table of Contents, I have other sites with material you might find useful.....
Tutorials about the free database supplied with Open Office version 2. (If you experienced Adabas with Star Office, ooBase is nothing like it!)
Some pages for programmers.
Using the parallel port with programs written in Delphi.
Links to other peoples' pages you may find useful
For you! A short list of other sites which I have personally visited and like.
Please visit the following to help make my site better known...
Top 100 Borland
Also, if you visit 1&1's site from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service.
Ad from page's editor: Yes.. I do enjoy
compiling these things for you... hope they are helpful. However..
this doesn't pay my bills!!! If you find this stuff useful, (and you
run an MS-DOS or Windows PC) please visit my freeware and shareware
page, download something, and circulate it for me? Links on your page
to this page would also be appreciated!
Click here
to visit editor's Sheepdog Software (tm) freeware, shareware pages.
And if you liked that, or want different things, here are some more pages from the editor of these tutorials....
Click here
to visit the homepage of my biggest site.
Click here
to visit the homepage of Sheepdogsoftware.co.uk. Apologies if the "?FrmTut" I added to that link cause your browser problems. Please let me know, if so?
Click here
to visit editor's pages about using computers in Sensing and Control, e.g. weather logging.
Link to editor's oldest homepage.
To email this page's editor, Tom Boyd....
Editor's email address. Suggestions welcomed!
Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org
Why does this page cause a script to run? Because of the Google panels, and the code for the search button. Why do I mention the script? Be sure you know all you need to about spyware.
....... P a g e . . . E n d s .....