| 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 Turbo Pascal, and to 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:
|
Preparations
- If you haven't done so already, create a new folder (directory, as they said in the old days) \DelphiLa on your harddisk (C: or D: or ...). Next, download the first series of lessons les0103.zip from the Downloads section and unzip it to this directory.
- If you haven't done so already, create directory EuroCCEN "under" \DelphiLa. Next, download euroccen.zip (source code for the first finished project) from the Downloads section and unzip it to this directory. When checking with Windows Explorer, you'll see euroccen.dpr, euroform.dfm and euroform.pas.
- Now start the introduction lesson: in Windows Explorer, doubleclick on index.html (in folder \DelphiLa). You're all set to follow the first lesson offline!
Euro Currency Convertor: compilation
Our very first project is a Euro Currency Convertor. The English ready-to-go version is called EuroCCEN. You compile and test it as follows:- Doubleclick in Windows Explorer (or in My Computer) on euroccen.dpr: Delphi starts and it opens the project "euroccen".
- Open Delphi's Run menu and click Run.

- Your project is compiled and linked: the result is euroccen.exe. Immediately after that, the program euroccen.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!

- Enter a new valid number in the EDIT-box, for example: 25. Click on the button with the caption "equals". In the right frame, you should see the corresponding amounts in the other European currencies.
- Click on one of the radiobuttons for the starting currency, for example BEF/LUF. Note that the corresponding label for Belgian en Luxemburg frank becomes invisible. That's because I found it quite silly if the program should show that 25 BEF = 25 BEF... On top of that, this trick gives a clear visual feedback as to the starting currency.

- Click the radiobutton 4 for the number of decimals. All converted numbers now are shown with 4 decimals (after the decimal point or decimal comma). This is useful when converting small amounts of certain currencies, e.g. Lire (ITL = Italian Lire). For a display with two decimals, click on the corresponding radiobutton.
- 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!
- Click the OK button in order to close the error-dialogbox. Then press key F9 (this is the same as the menu-command Run). 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 it's OK button.
- Enter a number with a decimal fraction in the EDIT-box. For the decimal separator, you can type . (point, dot) as well as , (comma): not only 10.5 but also 10,5 is accepted. The program does this by looking at Windows' "Regional Settings" and by replacing the comma with a point. Or vice versa, of course. This is a golden tip if you make applications for both Anglo-Saxon and non-Anglo-Saxon users. Especially the Americans tend to forget that there are a few countries besides the US of A...
- Type a number in the EDIT-box and press the ENTER key: just as if you clicked the "equals" button! This gimmick is programmed as follow: if the EDIT-box has the focus (meaning: if the text-cursor is visible in this object) and if you press ENTER, a click on the "equals" button is simulated.
- Stop the program via it's menu and Exit, via it's sytem menu, or via it's Close-button (top right of the window).
- 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.
Euro Currency Convertor as a standalone program
- Start Windows Explorer and look in the folder where our first project is located. You will see several additional files:
- euroccen.exe is the executable file
- euroform.dcu (dcu= Delphi compiled unit) is the file that was compiled from the source files euroform.pas (pas= Pascal) and euroform.dfm (dfm= Delphi Form)
- euroccen.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!
- other files: if you fooled around with the project. In the next lessons I'll discuss all those Delphi-files in detail.
- Doubleclick on euroccen.exe: the program starts.
- Try again to convert an illegal value. Now, you will only see the programmed error message.
- Stop the program.
- If you want to see how EuroCC reacts to a different setting of the "decimal separator", you open Windows' Control Panel, you open the Regional Settings and you change the "Decimal symbol": enter a point if it was a comma (or the opposite: enter a comma if it was a point). Close the window Regional Settings.
- Start EuroCCEN from the Explorer and note that the results are displayed differently: with decimal points instead of comma's (or the opposite, of course). Try a value with a decimal fraction: also in the EDIT-box this same decimal separator is shown, no matter if you type point or comma.
- Stop the EuroConvertor. Afterwards, don't forget to reset your Regional Settings back to the way they were.
discuss this topic to forum
