Delphi's Code Structure

Delphi's Code Structure

For people who are new to Delphi, I would like to:

The Delphi programming language is Pascal based. Therefore, spelling rules, block control statements and variable definition form are taken from Pascal. Therefore, it is relatively easy for those with Pascal knowledge to learn Delphi.

Delphi codes are modular (code snippets). You might think like Lego pieces. Each module can have sub-modules. These modular structures are called Procedure or Function. When you write a code snippet, you must give a name using one of these two statements.

Procedure Collection (x, y, z: Integer);
z: = x + y;


Function Collection (x, y, z: Integer): Integer;
z: = x + y;

as. All codes Begin Begin End; Each line of code must be written in ”; 

We write them by combining them with “. Çalıştır to change properties linked to an object, to execute procedures or functions.

Form1.Caption:=”Delphi öğreniyorum”

When assigning a value to a variable or a property, Bir: = ene is used.

When calling a B module of module A only


you just need to type.

To recall C, which is the sub-module of module B when in module A


you need to write.

Delphi Code Window

If you double-click on Form1, the code window opens. You will see takım Unit1.Pas if on the window and you'll see a number of expressions inside the window. The double-click procedure is the defined event of that object. Here is Form1’in


is the default event. We need to code the works that we want to do when creating this form. For example, the form's size, color, how to open ren.

For each added form, a new code file (extension) is created with the extension yeni .pas Her. The first form is the main form (you can change it later if you wish). The first form's code will run when your program runs. Now click the Events tab from Object Inspector, and then click on the On Click feature and double-click.

Begin ... End; If you write aç Form1. gil and wait for a few seconds, a window will appear with all the properties of Form1, the types of these properties and the values ​​that will be received.



The entire code window is:

Unit: The name of the code fragment. Here are the codes of Form1. Since it is not yet saved, it appears as ”Unit1.

Interface: Indicates that the interface of the program has started

Uses: This program shows the code libraries of objects to be used. So-called tool rooms.

Type: Defines the objects, procedures and functions to be used in the program.

TForm1 = Class (TForm): Describes the TForm object as TForm1 for this program. Immediately below this is the procedure under TForm1.

Private: Other objects, procedures that TForm1 objects that are linked to TForm1 can be used.

Public: Objects, procedures and other forms of TForm1 can be used.

Yes: This section describes the global variables of TForm1. TForm1 is a virtual object that is the same as TForm. Objects are not used directly in the program. Instead, it is transferred to the variable. Because the same object can be used elsewhere (such as taking a picture of an object, you can take as many photos as you want, the object stops where it stops). The TForm1 object is passed to the Form1 variable. All processes are handled with this Form1. The name of the bearer of all objects connected to this form is Form1. Changes to Form1 are transferred to the TForm1 object.

Implemantation: Indicates that the program codes have started.

{$ R, * .DFM}: Shows how to compile the program.

Unit1 ends with dotted end bit end. Unit.

We created FormCreate and FormClick procedures of TForm1. Because the FormCreate procedure contains no code, it will be deleted during the compilation. FormClick proceduru will automatically activate when clicked on the form and execute the codes it hosts. The expression TObject: Sender in parentheses is a statement that delphi has added to itself, so that the active object is understood.

Now, press the green right arrow button or F9 ′ to run the pogram. If you click Form1 when the program runs, you will see Form1 turning red.

Close the program (by pressing the X button in the upper right corner of Form1) and return to the delphi environment. From the Project menu, click Options and open the Application tab.

In Title, type anything you want, select icon (icon in the Borland Shared-Images folder under the folder where you are loading delphiyi) and click OK. From the File menu, click SaveAll and save our program. The codes of each form opened must be saved as a separate file. We have recorded all forms (here we have a single form)