Delphi source Program Format Writing specification (i) (1)

Source: Internet
Author: User
Tags exception handling reserved

1, Introduction to the specification

This code mainly stipulates the Delphi source program in the writing process should follow the rules and precautions. The purpose of writing this specification is to keep the code writing habits of the company's software developers consistent. This allows each team member to understand the other team's code, so that the two development of the source code memory system maintenance.

2, General format specification

2.1 Indent

Indentation is the two spaces that are exposed when the level of the source program changes to increase readability. The rules for indenting indent two spaces per level. You are not allowed to use tab. Because the tab will have different effects because the user has made different settings. When encountering begin or enter judgment, loop, exception handling, with statement, record type declaration, class declaration and so on, add a level, when encountered end or exit judgment, loop, exception handling, with statement, record type declaration, class declaration and so on to reduce one level. For example:

If Tmpint <> Then
Tmpint: = 100;

2.2 Begin. End

The BEGIN and END statements are exclusive to one line in the source program, for example:
For I: = 0 To do begin//incorrect usage
End
For I: = 0 todo//correct usage
Begin
End

2.3 Spaces

Add spaces at both ends of the operator and logical judgment symbol, for example: I: = i + 1;,a and B, but no spaces are required to add parentheses. For example: if (a > B) then//Error usage
If (A > B) then//correct usage
Another example: Procedure Test (Param1:integer; param3:string);

3. Object Pascal Grammar Writing format specification

3.1 Reserved words

The reserved words or keywords of Object Pascal language should all use lowercase letters.


3.2 Procedures and functions

3.2.1 Nomenclature and format

The names of procedures and functions should all be made up of meaningful words, and the first letter of all words should use uppercase letters. For example:
Procedure formatharddisk;//Incorrect naming
Procedure formatharddisk;//the right name

Procedures and functions that set the contents of a variable should be prefixed with a set, for example: procedure Setusername;

Procedures and functions that read the contents of a variable should be prefixed with GET, for example: function getusername:string;

Parameters for 3.2.2 Procedures and functions

3.2.2.1 naming

The parameters of the unified type are written in the same sentence: procedure Foo (Param1, Param2, Param3:integer; param4:string);

3.2.2.2 naming

All parameters must be meaningful and, when the parameter name and other attribute names are heavy, add a prefix of ' a ', for example:
Procedure Someproc (ausername:string; Auserage:integer);

3.2.2.3 Naming conflicts

When a function or procedure of the same name is included in the two unit used, then when you reference the function or procedure, the function or procedure in the unit that is declared after the use clause is executed. To avoid this ' uses-clause-dependent ' need to write the full function or process from the reference function or procedure. For example:

Sysutils.findclose (SR);
Windows.findclose (Handle);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.