|
When programming in Pascal goes beyond the DOS command prompt, you'll probably use Delphi. Delphi is a Rapid Application Development (RAD) system for Windows which you can use to compile Windows applications. This course will introduce you to the Delphi programming interface. Delphi? Does it rhyme with Sci-Fi? Those of you who are familiar with Windows programming might know Microsoft's Visual Basic (VB), a RAD development system similar to Delphi. Both boast of featuring Visual Development, Object-Orientated Programming (OOP) and user-friendiness. Well then, since they're so similar, why should we use Delphi instead of Visual Basic?
The latest version of Delphi currently is Delphi 4. However, because it's too recent, we've been unable to cover it in our course. You might want to learn more about it from the Inprise website at www.inprise.com. Don't worry too much about compatibility though, our code should be compatible with version 2 and above of Delphi, including version 4. How do we use Delphi?
There's no better way to learn than to try it out yourself. We'll teach you the three steps of drawing, modifying, and coding by creating an example program which changes the form's caption to 'Hello World!' when you click on a label. First, select the 'File' menu, then select 'New Application'. You'll be presented with a blank new window with dots all over. (You could say it has a bad case of measles, though that's pretty contrived.) This window is referred to as a form. Select the tab labelled 'Standard' and click on the button with an A on it. Drag across the form to create a label. (You might have realized that the dots were a snap-to grid - They'll activate when creating, moving, and resizing components.) If all worked well, you should have a brand new label on the form with the caption 'Label1'. Congratulations! For this simple program, you've already finished the first step: Drawing. Of course, in more complex programs, you would need more than just a mere label...
Enough. Now that you have customised what you have 'drawn', the next step is to add code to each object. Look back at your Object Inspector. Notice that you've only been looking at the 'Properties' tab, the one you used to change your 'drawing'? Click on the second tab 'Events', and voila! You see the list of events linked to the object that is currently selected. For instance, the 'OnClick' event is activated when the object currently selected is clicked. Considering that you haven't done anything wrong, the following steps would create a 'Hello World!' application.
Wait for a moment as your hard disk lights flash... Poof! Instantly, a great window appears on your screen, beckoning you to click on its label. Do so. At once, the title bar changes to say 'Hello World!' It works! Your first Delphi program works! Let's look at your code: First of all, as your code was for the label's OnClick event, your code would only be executed when the label gets clicked. Click anywhere else and it won't work. When you do click it, it sets the Caption member of Form1, which is the form, to become 'Hello World!' Huh? Well, look at it this way. Notice that the statement construct is similar to that of a record? That's because Form1 is an object - Just treat it as a record for now and you'll be fine. End Of Introduction Now that you understand Delphi basics, you can go on to learn about some basic Windows Programming concepts. Go on to the next course to learn more. |
|