Crash Course Delphi, part 1: Compiling a Delphi project


Turbo Start

Delphi combines the user-friendlyness of Visual Basic with the precise control and speed of C++. Without lots of "real" programming, you can develop very efficient and fast Windows applications.

Delphi is a RAD tool, Rapid Application Development. It reduces the complicated task of programming Windows applications to the handling of "objects" in a visual environment.

Typing of source code is limited to a strict minimum. As a result, you can fully concentrate on what the program should do: this is top-down programming at its highest level, designing a nice Windows GUI interface becomes a breeze. You don't have to "program" any standard Windows elements, just a few mouse clicks and there's your fully functional listbox, file dialog box, or even a full fledged database grid.

With Delphi, debugging is limited to the program lines that you entered yourself, because all the ready-made modules that you use are tested and ready-to-go.

Compared to the limited possibilities of Visual Basic or the complexity of C++, Delphi is really refreshing. Once you've used Delphi, you'll be fascinated by its sheer development speed.

For starters, a few general things about this Delphi Tutorial:

Will it work with Delphi Professional Rio or Delphi 2007 or ...? All of the lessons were written for Delphi Community Edition 10.3 (2018). They are 100% compatible with all the higher editions, and even with most older editions.
VCL, IDE, OOP...? In order to get you up to speed quickly on acronyms, in one of the first lessons of our second tutorial, we'll make the program Acron.

For those who are too impatient: the exe-file of Acron can be found in the Downloads section as ACRONX.ZIP. Also download ACRODAT4.ZIP: it contains the list of acronyms. This list will grow. Every new and enhanced version will get a higher number (yep, the next one will be ACRODAT5.ZIP, and afterwards..., and so on).
Run before you can walk? Yes, that's possible with Delphi. No need to start studying the old Turbo Pascal, no need to know anything about OOP (Object Oriented Programming). Just learn as you practice, and we'll fill in the gaps later on.

So, no traditional "Hello, World" proggie in our tutorial. We'll start immediately with a real application. After all, it's R.A.D time -- let's go!

Preparations

  1. If you haven't done so already, create a new folder ("directory", as they said in the old days) \DelphiLand on your harddisk.
  2. If you haven't done so already, create directory Foot2Meter "under" \DelphiLand.
  3. Next, if you are using Delphi:
    Download foot2meter.zip (Delphi source code for the first finished project) from the Downloads section and unzip it to this directory. When checking with Windows Explorer, you should see foot2meter.dpr, unit1.dfm and unit1.pas.

 

 

Foot-to-Meter convertor: compilation

Our very first project is a Foot-to-Meter Convertor. The English ready-to-go version is called Foot2Meter. You compile and test it as follows:
  1. Doubleclick on foot2meter.dpr: Delphi will start and it opens the project "foot2meter".
  2. Open Delphi's Run menu and click Run.

    RUN menu
  3. Your project is compiled and linked: the result is foot2meter.exe. Immediately after that, the program foot2meter.exe is launched. All this happens so fast, that you probably even didn't notice that your source code was compiled into an executable program!

    foot2meter
  4. Enter a valid number in the first EDIT-box, for example: 5. Also enter a valid number in the second EDIT-box, for example: 3. Click on the button with the caption "Convert". On the right, you should see the corresponding length in meter.
  5. Click on the radiobutton "Meter to foot / inch". Note that the label for inches becomes invisible.

    foot2meter
  6. Enter an invalid value in the EDIT-box (like 20,5,7 or ABC) and try a conversion. Delphi responds with an error message and pauzes the execution of the application: when trying to convert the text '20,5,7' or 'ABC' to a number, Delphi's Debugger noted the error condition. The Debugger shows design errors as well as runtime errors!

    Error message from Delphi
  7. Click the Continue button in order to close the error-dialogbox. Execution of the program is resumed and you see a second error message. This is the warning we programmed ourselves. Only this message will be shown when there is an invalid input when you run the program from Windows Explorer or from My Computer. Also close this dialogbox by clicking its OK button.

    warning
  8. Stop the program via its menu and Exit, via its sytem menu, or via its Close-button (top right of the window).
  9. Stop Delphi. If you get the question "Save changes to...?", say no. Because maybe you changed something in the source code and for the moment we don't want to save these changes.

Foot2Meter as a standalone program

  1. Start Windows Explorer and look in the folder where our first project is located. You will see several additional files:
     
    • foot2meter.exe is the executable file
    • foot2meter.dcu (dcu= Delphi compiled unit) is the file that was compiled from the source files (.pas= Pascal) and form files (.dfm= Delphi Form)
    • foot2meter.dsk (dsk= Desktop) is the file that remembers how your Delphi-desktop looked like when you stopped Delphi. Next time when you open the same project, the positions and dimensions of all the windows will be restored. Nifty!
    • some other files for Delphi's housekeeping. In the next lessons we'll discuss all those Delphi-files in detail.
  2. Doubleclick on foot2meter.exe: the program starts.
  3. Try again to convert an illegal value. Now, you will only see the programmed error message.
  4. Stop the program.

LESSON 2 Lesson 2