Delphi XE5 tutorial 5: program structure and syntax

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Content from Delphi XE5 UPDATE 2 "Delphi Reference" official help, my level is limited, welcome expert correction of errors´╝ü

Also welcome to Delphi learning materials to finished, are interested in can QQ:

1 Program Structure and Syntax

1Program structure and syntax


A complete, executable Delphi application consists of multiple unit modules, all tied together by a single source code module called a project file. In traditional Pascal programming, all source code, including the main program, is stored in .pas files. Embarcadero tools use the file extension .dpr to designate the main program source module, while most other source code resides in unit files having the traditional .pas extension. To build a project, the compiler needs the project source file, and either a source file or a compiled unit file for each unit.

A complete, executable Delphi application consists of multiple modules. A project file called a single source code file and binds them together. Each unit is stored in a separate file and compile, compiled unit is linked to the program. In traditional Pascal programming, all source code, including the main program are stored in the.Pas file. Embarcadero tools use a project file (.Dpr) to store the ‘ ’ program, and most of the source code is stored in the unit file (.Pas). To build a project, the compiler needs to project source files, as well as a source file or per unit of a compiled unit file.


Note: Strictly speaking, you need not explicitly use any units in a project, but all programs automatically use the System unit and the SysInit unit.

Note: strictly speaking, you don't need to explicitly use any a project unit, but all programs automatically using the System unit and SysInit unit.

The source code file for an executable Delphi application contains:

Contains an executable Delphi application source code file:

a program heading,

A program header(program heading),

a uses clause (optional), and

A uses clause (optional), and

a block of declarations and executable statements.

A statement and command statement block(block).


The program header specifies the program name; uses clause lists units used by the program; block contains a statement and command statement.


The compiler, and hence the IDE, expect to find these three elements in a single project (.dpr) file.

When the program runs, these commands will be executed. IDE desired in a project file (.Dpr) found in the above three kinds of elements.


1.1  The Program Heading

1.1   Program head

The program heading specifies a name for the executable program. It consists of the reserved word program, followed by a valid identifier, followed by a semicolon. For applications developed using Embarcadero tools, the identifier must match the project source file name.

The program header specifies the name of the executable program. It is a reserved word program, then it is a valid identifier, followed by a semicolon. For the use of Embarcadero tools development program, the identifier must project the source file name matching.


The following example shows the project source file for a program called Editor. Since the program is called Editor, this project file is called Editor.dpr.

The example below shows a program called Editor project source files. It begins with the keyword program, followed by a valid identifier (specifies the program), and end with a semicolon. Symbol must and project file names are the same, in this case, because the program is called Editor, the project file should be EDITOR.dpr.


program Editor;

 

  uses Forms, REAbout, // An "About" box

       REMain;         // Main form

 

  {$R *.res}

 

  begin

   Application.Title := 'Text Editor';

   Application.CreateForm(TMainForm, MainForm);

   Application.Run;

  end.



The first line contains the program heading. The uses clause in this example specifies a dependency on three additional units: Forms, REAbout, and REMain. The $R compiler directive links the project's resource file into the program. Finally, the block of statements between the begin and end keywords are executed when the program runs. The project file, like all Delphi source files, ends with a period (not a semicolon).

The first line contains the program head. The uses clause in the example specifies the dependence of it with the other three units: Forms, REAbout, and REMain. $R compiler directive to link project resource file into the program. Finally, will block is performed between begin and end when the program is run. As with all source files, project file to a period (not a semicolon) end.


Delphi project files are usually short, since most of a program's logic resides in its unit files. A Delphi project file typically contains only enough code to launch the application's main window, and start the event processing loop. Project files are generated and maintained automatically by the IDE, and it is seldom necessary to edit them manually.

Delphi project file is usually very short, because the vast majority of the program logic file located in the unit. The main window of an Delphi project file typically contains only enough code to start the application, and start the event processing cycle. The project file is generated automatically by IDE and auto maintenance, rarely need to manually edit.


In standard Pascal, a program heading can include parameters after the program name:

In standard Pascal, behind the program name program head includes parameters:

program Calc(input, output);

Embarcadero's Delphi ignores these parameters.

Embarcadero Delphi ignores these parameters.


In RAD Studio, the program heading introduces its own namespace, which is called the project default namespace.

In RAD Studio, the program header into your own namespace, which is called the default namespace.


1.2  The Program Uses Clause

The uses Clause 1.2 program

The uses clause lists those units that are incorporated into the program. These units may in turn have uses clauses of their own. For more information on the uses clause within a unit source file, see Unit References and the Uses Clause, below.

The uses clause lists together constitute the program unit, the unit may contain an uses clause itself. A uses clause, please reference cell references and uses clause.


The uses clause consists of the keyword uses, followed by a comma delimited list of units the project file directly depends on.

The uses clause contains the keyword uses, followed by the project file units list, separate.


1.3 The Block

1.3 Block


The block contains a simple or structured statement that is executed when the program runs. In most program files, the block consists of a compound statement bracketed between the reserved words begin and end, whose component statements are simply method calls to the project's Application object. Most projects have a global Application variable that holds an instance of Vcl.Forms.TApplication, Web.WebBroker.TWebApplication, or Vcl.SvcMgr.TServiceApplication. The block can also contain declarations of constants, types, variables, procedures, and functions; these declarations must precede the statement part of the block. Note that the end that represents the end of the program source must be followed by a period (.):

The block contains a simple statement or statements, executed when the program runs it. In most applications, the block contains a compound statement, it (a compound statement) by the keyword up begin and end, which commands simply call Application object. Most projects have a global Application variable, it is Vcl.Forms.TApplication, Web.WebBroker.TWebApplication, or Vcl.SvcMgr.TServiceApplication as an example. Block may also contain constants, types, variables, procedures and functions of the statement, they must be in the (block) command statement part (front). Need to pay attention to is, said the source end end must be followed by a period(.):

begin

  .

  .

  .

end.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Beau at February 18, 2014 - 7:20 AM