|Understanding the Delphi unit source|
|Page 1: Delphi Unit source code|
Welcome to the fifth chapter of the FREE online programming course:
Understanding the unit source
As you know already by now, forms are visible building blocks of all (well, at least 99%) Delphi projects. Each form in a Delphi project has an associated unit. The unit contains the source code for any event handlers attached to the events of the form or the components it contains.
The best way to describe the unit code is to take a look at the source. For the moment reefer to the example in the last chapter, especially the unit source. After we have placed a Label, an Edit box and a Button, and added an OnClick event handling procedure for the button, the source code looked like:
We'll now explore and try to figure what each line stands for. First, a note: Delphi units follow a predefined format. For example, the UNIT keyword must be the first line in the source, followed by INTERFACE... This strict format is "predefined" by Delphi, meaning that when you add an empty form to a project, its associated unit source is already created with special keywords and type declaration. When you add a component on a form and write an event handler for it, Delphi will place the corresponding code at the exact location in the unit file.
Note another thing: in the above code, black lines appear in the forms unit source the first time you add a form to a project. Lines colored in green were added by Delphi when you have placed those three components on a form. Lines in red were added by you in the previous chapter. Whenever you create a new form, Delphi creates the corresponding unit file with the skeleton code marked black.
The rest of the article will discuss parts of the unit source. Several new words like class, object and similar will be mentioned, do not get frightened if you do not understand what they mean, let's just say that such words are a part of Delphi object oriented programming, we will discuss them in the following chapters more clearly.
A Beginner's Guide to Delphi Programming: Next Chapter >>