1. Introduction to specifications
This specification mainly stipulates the rules and precautions that should be followed during the writing process of Delphi source programs. The purpose of writing this specification is to make the source code writing habits of the company's software developers consistent. This allows each team member to understand the code of other team members, which facilitates the maintenance of the secondary development memory system of the source code.
2. General format specifications
2.1 Indentation
Indentation is two spaces exposed to increase readability when the source program level changes. The indentation rule is two spaces per level. Tab is not allowed. Because Tab will produce different effects due to different settings made by the user. When encountering begin or entering judgment, loop, exception handling, with statement, record type declaration, class declaration, etc., increase one level. When encountering end or exiting judgment, loop, exception handling, with statement, record type declaration, The class declaration is reduced by one level when waiting. For example:
if TmpInt <> 100 then
TmpInt := 100;
2.2 Begin..End
The begin statement and the end statement must occupy one line in the source program, for example:
for I := 0 to 10 do begin //Incorrect usage
end;
for I := 0 to 10 do //Correct usage
begin
end;
2.3 spaces
Add spaces at both ends of operators and logical judgment symbols, such as: I := I + 1;, a and b, etc., but no spaces are required when adding parentheses. For example: if ( a > b ) then //wrong usage
If (a > b) then //Correct usage
Another example: PRocedure Test(Param1: integer; Param3: string);
3. Object Pascal syntax writing format specification
3.1 Reserved words
Reserved words or keywords in the Object Pascal language should be written in all lowercase letters.
3.2 Procedures and functions
3.2.1 Naming and format
Procedure and function names should consist entirely of meaningful words, and the first letter of all words should be capitalized. For example:
procedure formatharddisk;//incorrect naming
procedure FormatHardDisk;//Correct naming
Procedures and functions that set the contents of variables should be prefixed with Set, for example:
procedure SetUserName;
Procedures and functions that read the contents of variables should use Get as a prefix, for example:
function GetUserName: string;
3.2.2 Parameters of procedures and functions
3.2.2.1 Naming
Parameters of the same 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 is the same as the name of other attributes, add a prefix 'A', for example:
procedure SomeProc(AUserName: string; AUserAge: integer);
3.2.2.3 Naming conflict
When the two units used include a function or procedure with the same name, then when you reference this function or procedure, the function or procedure in the unit declared later in the use clause will be executed. To avoid this 'uses-clause-dependence', you need to write the complete source of the function or procedure when referencing it. For example:
SysUtils.FindClose(SR);
Windows.FindClose(Handle);
3.3 Variables
3.3.1 Variable naming and format
First, all variables must have meaningful names so that other team members can easily understand the meaning of the variables. Variable naming can use synonymous English names. Several English words can be used, but the first letter of each word must be capital. For example:
var
WriteFormat::string;
At the same time, certain abbreviations can be used for some specific types as follows:
pointer type
P
record type
Rec
array type
Arr
kind
Class
Loop control variables usually use a single character such as: i, j, or k. It is also allowed to use a meaningful name such as UserIndex.
3.3.2 Local variables
Using local variables within a procedure follows the naming rules for all other variables.
3.3.3 Global variables
Try not to use global variables. If you must use global variables, you must add the prefix 'g', and the type of the variable should be reflected in the variable name. For example:
gprecUserCount: point;//Global variable named UserCount, its type is a pointer to a structure
But global variables can be used inside modules. All global variables within the module must be prefixed with 'F'. If data needs to be exchanged between several modules, this needs to be achieved by declaring attributes. For example:
type
TFormOverdraftReturn = class(TForm)
private
{Private declarations}
FuserName: string;
FuserCount: Integer;
Procedure SetUserName(Value: string);
Function GetUserName: string;
public
{Public declarations}
property UserName: string read GetUserName write SetUserName;
property UserCount: Integer read FuserCount write FuserCount;
end;
3.4 Type
3.4.1 Case protocol
Type names for reserved words must be all lowercase. Win32 API types are usually all capitalized. For other types, the first letter is capitalized and the remaining letters are lowercase. For example:
var
MyString: string; // reserved Word
WindowHandle: HWND; // Win32 API type
I: Integer; // type identifier introduced in System unit
3.4.2 Floating point types
Try not to use the Real type. It is just for compatibility with the old Pascal code. Try to use the Double type. The Double type is optimized for processors and data buses and is a standard data structure defined by IEEE. When the value exceeds the range of Double, use Extended. But Extended is not supported by Java. However, the Single type may be used when using DLLs written in other languages.
3.4.3 Enumeration types
The name of the enumeration type must be meaningful and the type name must be prefixed with 'T'. The name of the content of the enumeration type must contain the abbreviation of the enumeration type name, for example:
TSongType = (stRock, stClassical, stCountry, stAlternative, stHeavyMetal, stRB);
3.4.4 Array types
The name of the array type must be meaningful and the type name must be prefixed with 'T'. If you declare a pointer to an array type you must prefix the name of the type with 'P', for example:
type
PCycleArray = ^TCycleArray;
TCycleArray = array[1..100] of integer;
3.4.5 Record types
The name of the record type must be meaningful and the type name must be prefixed with 'T'. If you declare a pointer to an array type you must prefix the name of the type with 'P', for example:
type
PEmployee = ^TEmployee;
TEmployee=record
EmployeeName: string
EmployeeRate: Double;
end;
Category 3.5
3.5.1 Naming and format
Class names must be meaningful and type names must be prefixed with 'T'. For example:
type
TCustomer = class(TObject)
The name of a class instance is usually the name of the class minus the 'T'. For example:
var
Customer: TCustomer;
3.5.2 Variables in classes
3.5.2.1 Naming and format
Class names must be meaningful and type names must be prefixed with 'F'. All variables must be four-dimensional. If you need to access this variable from the outside, you need to declare an attribute
3.5.3 Method
3.5.3.1 Naming and format
Same naming and format for functions and procedures.
3.5.3.2 Property access methods
All property access methods must appear in private or protected. The naming of attribute access methods is the same as that of functions and procedures. In addition, the reader method must use the prefix 'Get'. The writer method must use the prefix 'Set'. The parameter of the write method must be named 'Value', and its type must be consistent with the property to be written. For example:
TSomeClass = class(TObject)
private
fsomeField: Integer;
protected
function GetSomeField: Integer;
procedure SetSomeField( Value: Integer);
public
property SomeField: Integer read GetSomeField write SetSomeField;
end;
3.6 Properties
3.6.1 Naming and format
Consistent with the name of the class variable prefixed with 'F' that it is used to operate on.
3.7 Documentation
3.7.1 Project files
3.7.1.1 Project directory structure
Program home directory--Bin (the path where the application is located)
-Db (path to local database)
-Doc (path where the document is located)
-Hlp (path to help file)
-Backup (backup path)
-Tmp (temporary file path)
3.7.1.2 Naming
The project file must have a meaningful name. For example: The project file of system information in Delphi is named SysInfo.dpr.
3.7.2 Form file
3.7.2.1 Naming
Consistent with the name of the Form: For example: if the name of the Form is FormMain, the name of the Form file will be FormMain.frm.
3.7.3 Data Module file
3.7.3.1 Naming
Data module files should be named meaningfully and prefixed with 'DM'. For example: The user data module is named 'DMCustomers.dfm'.
3.7.4 Remote Data Module files
3.7.4.1 Naming
The remote data module file should be named meaningfully and use 'RDM' as the prefix. For example: the user's remote data module is named 'RDMCustomers.dfm'.
3.7.5 Unit file
3.7.5.1 Ordinary Unit
3.7.5.1.1 Unit file naming
Unit files should be named meaningfully and use 'unit' as a prefix. For example: A general unit is named 'UnitGeneral'.
3.7.5.2 Form Units
3.7.5.2.1 Naming
The name of the Form unit file must be consistent with the name of the Form. For example: if the main form is called FormMain.pas, then the name of the Form Unit file is: UnitFormMain.
3.7.5.3 Data Module Units
3.7.5.3.1 Naming
The name of the Data Module unit file must be consistent with the name of the Data Module. For example: if the main Data Module is called DMMain.pas, then the name of the Data Module Unit file is: UnitDMMain.
3.7.5.4 File header
The purpose, author, date, input and output of the file should be written at the head of all files. For example:
{
Modification date:
author:
use:
The structure of this module consists of:
}
3.7.6 Forms and Data Modules Forms
3.7.6.1 Form class
1. Form class naming standards
Forms classes should be named meaningfully and prefixed with 'TForm'. For example: The name of the About Form class is:
TAboutForm = class(TForm)
The name of the main form is
TMainForm = class(TForm)
2. Naming standards for Form class instances
The name of the Form class instance should be consistent with the name of the Form class with the 'T' removed. For example:
Type Name
Instance Name
AboutForm
AboutForm
TmainForm
MainForm
TCustomerEntryForm
CustomerEntryForm
3.7.6.2 Data Modules Form
3.7.6.2.1. Data Module Form Naming Standard
Data Modules Forms classes should be named meaningfully and use 'TDM' as prefix. For example:
TDMCustomer = class(TDataModule)
TDMOrders = class(TDataModule)
3.7.6.2.2. Data Module instance naming standards
The name of the Data Module Form class instance should be consistent with the name of the Data Module Form class with the 'T' omitted. For example:
Type Name
Instance Name
TCustomerDataModule
CustomerDataModule
TordersDataModule
OrdersDataModule
3.8 Controls
3.8.1 Naming of control instances
Instances of a control should be prefixed with the name of the control class minus the 'T', for example:
The name of Tedit where the user name is entered is: EditUserName.
3.8.2 Abbreviation of control
The following abbreviations can be used for the name of the control, but the abbreviation used is added with '_' between the control names:
3.8.2.1 Standard Tab
mm TMainMenu
pm TPopupMenu
mmiTMainMenuItem
pmiTPopupMenuItem
lblTLabel
edt TEdit
mem TMemo
btn TButton
cb TCheckBox
rb TRadioButton
lb TListBox
cb TComboBox
scbTScrollBar
gb TGroupBox
rg TRadioGroup
pnlTPanel
cl TCommandList
3.8.2.2 Additional Tabs
bbtn TBitBtn
sbTSpeedButton
me TMaskEdit
sg TStringGrid
dgTDrawGrid
imgTImage
shp TShape
bvl
sbxTScrollBox
clb TCheckListbox
spl TSplitter
stx TStaticText
cht TChart
3.8.2.3 Win32 Tab
tbcTTabControl
pgcTPageControl
ilTImageList
re TRichEdit
tbr TTrackBar
prb TProgressBar
ud TUpDown
hk THotKey
ani TAnimate
dtpTDateTimePicker
tvTTreeView
lv TListView
hdrTHeaderControl
stb TStatusBar
tlb TToolBar
clbTCoolBar
3.8.2.4 System Tab
tm TTimer
pb TPaintBox
mpTMediaPlayer
olec TOleContainer
ddccTDDEClientConv
ddciTDDEClientItem
ddscTDDEServerConv
ddsiTDDEServerItem
3.8.2.5 Internet Tab
cskTClientSocket
sskTServerSocket
wbd TWebDispatcher
pp TPageProducer
tp TQueryTableProducer
dstp TDataSetTableProducer
nmdt TNMDayTime
nec TNMEcho
nf TNMFinger
nftpTNMFtp
nhttpTNMHttp
nMsg TNMMsg
nmsgTNMMSGServ
nntp TNMNNTP
npop TNMPop3
nuup TNMUUPProcessor
smtp TNMSMTP
nst TNMStrm
nsts TNMStrmServ
ntm TNMTime
nudpTNMUdp
psk TPowerSock
ngs TNMGeneralServer
htmlTHtml
urlTNMUrl
smlTSimpleMail
3.8.2.6 Data access Tab
dsTDataSource
tbl TTable
qry TQuery
spTStoredProc
dbTDataBase
ssn Tsession
bmTBatchMove
usql TUpdateSQL
3.8.2.7 Data Controls Tab
dbgTDBGrid
dbn TDBNavigator
dbtTDBText
dbeTDBEdit
dbm TDBMemo
dbiTDBImage
dblb TDBListBox
dbcb TDBComboBox
dbch TDBCheckBox
dbrg TDBRadioGroup
dbll TDBLookupListBox
dblc TDBLookupComboBox
dbreTDBRichEdit
dbcgTDBCtrlGrid
dbchTDDBChart
3.8.2.8 Decision Cube Tab
dcb TDecisionCube
dcq TDecisionQuery
dcs TDecisionSource
dcp TDecisionPivot
dcg TDecisionGrid
dcgr TDecisionGraph
3.8.2.9 QReport Tab
qr TQuickReport
qrsd TQRSubDetail
qrb TQRBand
qrcb TQRChildBand
qrg TQRGroup
qrl TQRLabel
qrtTQRText
qre TQRExpr
qrs TQRSysData
qrm TQRMemo
qrrt TQRRichText
qrdr TQRDBRichText
qrsh TQRShape
qri TQRImage
qrdi TQRDBMImage
qrcr TQRCompositeReport
qrp TQRPreview
qrch TQRChart
3.8.2.10 Dialogs Tab
OpenDialog TOpenDialog
SaveDialog TSaveDialog
OpenPictureDialog TOpenPictureDialog
SavePictureDialog TSavePictureDialog
FontDialog TFontDialog
ColorDialog TColorDialog
PrintDialog TPrintDialog
PrinterSetupDialog TPrintSetupDialog
FindDialog TFindDialog
ReplaceDialog TReplaceDialog
3.8.2.11 Win31 Tab
dbll TDBLookupList
dblc TDBLookupCombo
tsTTabSet
ol TOutline
tnb TTabbedNoteBook
nb TNoteBook
hdrTHeader
flbTFileListBox
dlb TDirectoryListBox
dcb TDriveComboBox
fcb TFilterComboBox
3.8.2.12 Samples Tab
gg TGauge
cg TColorGrid
spb TSpinButton
speTSpinEdit
dol TDirectoryOutline
calTCalendar
ibea TIBEventAlerter
3.8.2.13 ActiveX Tab
cfx TChartFX
vspTVSSpell
f1bTF1Book
vtc TVTChart
grp TGraph
3.8.2.14 Midas Tab
prvTProvider
cdsTClientDataSet
qcds TQueryClientDataSet
dcomTDCOMConnection
oleeTOleEnterpriseConnection
sckTSocketConnection
rms TRemoteServer
mid TmidasConnection
4. Modify specifications
The provisions of this rule apply only to programs that have been included in configuration management. In this type of modification, it is required to retain the content before the modification and identify the modified and new content. And add necessary information such as the modifier, modification date, modification description, etc. to the file header.
4.1 Modify history records
When making approved modifications to a source file, the modifier should add a modification history item to the program file header. For each subsequent modification, the modifier must fill in the following information in the item:
Modifier
modification time
Reason for modification
Modification instructions are how to modify
4.2 Add new lines of code
New lines of code should be preceded and followed by comment lines.
// Modifier, modification time, modification description
Add new line of code
// End of modification
4.3 Delete lines of code
Use comment lines before and after deleting lines of code.
//Modifier, modification time, modification description
//Line of code to be deleted (comment the statement to be deleted)
//End of modification
4.4 Modify lines of code
Modify the code line by deleting the code line and then adding a new code line.
//Modifier, modification time, modification description
//Line of code before modification
//End of modification
//Modified line of code
Modified line of code
//End of modification