Purpose of writing
This specification defines the program files and coding style involved in the writing process of the program. This specification is developed based on the Delphi language.
Organization of project documents
In Delphi, program files are organized according to project units. In a typical project include:
Project files (.DRP files)
Contains the Pascal source code of the project's main program;
Unit files (.PAS files)
Pascal source file for each form in the project, including all declarations and procedures of the form (including time processing procedures);
Form files (.DFM files)
A binary file containing the design properties of a form. The .DFM file and .PAS file of each form correspond to each other;
Resource file (.RES file)
Compiled binary resource files that are linked into the application's executable file;
Project options file (.DOF file)
Stores the project options set by the PProject|Options menu command;
Desktop settings file (.DSK file)
Stores the desktop options set by the Tools|Options menu command;
Package file (.DPK/.BPL file)
Files used to share components, classes, data, and code. The source file is a .DPK file and after compilation it is a .BPL file;
constant definition
content:
Definition of logical values;
Definition of constant value;
Definition of error code;
Format: One definition per line. as follows:
Const<constant>: type = value; //Comment
illustrate:
Use the Const statement to declare constants that are used in place of literal values.
Example: Const C_SQL:string='select CH_USERER_ID from T_CD_USER'; //Query user ID
Const C_PI:real =3.1415926; //Pi
Structure type definition
Content: Structure type definition
Format:
Type
<Type name>//Structure description comments
<Variable name 1>: variable type; //variable description comments
<Variable name 2>: variable type; //variable description comments
…
End;
illustrate:
<Type name> is a string starting with an uppercase letter. The statements defining variable types in the structure definition begin in the second row and fifth column.
Example:
type
TableList=record //System tree unit type definition
InID: Integer; //unit number
Name: string; //Unit name
PID: string; //Previous unit name
PT: PTableList; //Pointer to the next unit type
end;
Programming style
Programming style specifies the positioning rules for each statement and the comments in the program.
Function/procedure style
<function/procedure> Name (variable: variable type [,...]);//function/procedure description
var
Variable 1: variable type; // variable description
Variable 2: Variable type; //Variable description
…
begin
statement;
statement;
…
end ;
Note: Variable declarations and statements are written starting from the third column. If there is indentation, indent it by two columns at a time and align with the corresponding statements.
statement style
illustrate:
There is usually one paragraph function description for every ten lines at most in the program body;
Standardize the use of various statements;
Indentation in statements is in units of two columns.
variable definition statement
var
var_name: <data type>;
assignment statement
var_name: = <expression>;
conditional statement
if condition then //Comment
begin
statement;
…
end
else if condition then//comment
begin
statement;
...
end
else//comment
statement;
Note: If there is only one execution statement, the begin and end statements can be omitted.
Loop statement
//Loop function annotation
for counter := start to end do
begin
[statement];
…
end;
//Loop function annotation
while [condition] do
begin
[statement];
…
end;
//Loop function annotation
repeat
[statement];
…
until [condition]
switch statement
//switch function description
case <expression> of
<value1>:[statement 1];
<value2>:[statement 2];
…
<valuen>: [statement n]
end;
Comment line
There must be "Module Description" and "Unit Description" comments for this unit file at the top of the program code unit file.
For meaningful code parts such as constants, structural types, functions/procedures, custom variables, code segment function blocks, key statements, etc.
points, there must be a comment line to explain in detail.
The comment line can be added with "//XXXXXXXX" after the line that needs to be explained, or it can also be added above the line that needs to be explained.
Add multiple lines using "{XXXXXXXX}" or add a single line using "//XXXXXXXX".
File and form naming
Meaning class name naming format
Project file Program(.DPR) XXXXX
UnitUnit(PAS) uXXXXX
FormForm.Name(.DFM) XXXXXFrm
Data moduleDataModule XXXXXDM
Unit header definition, added in front of each unit.
{************************************************ ****
Unit name:
Function description:
author:
Software name:
Version:
Company name: Sword as Dream Software Creation Studio
*************************************************** *** }
Software version number format definition:
The software uses the following version number format: XXXX
For example: after the releasable program is completed, the version number is marked as "1.0.0.0"
The first digit: version number. Note: This is a version of the software that has been significantly improved.
Second digit: Maintenance number. Note: Some errors have been modified based on the existing version.
The third digit: patch number. Note: When the program corrects some errors and no new maintenance number is formed, the patch number is used.
The fourth digit: correction number. Note: When an emergency program error occurs, the modified program is used as an identifier, not as the version number of the released program. yckxzjj