1. Introduction to the specifications
This specification mainly stipulates the rules and precautions that Delphi source programs should follow during the writing process. The purpose of writing this specification is to keep the source code writing habits of company software developers consistent. Doing so that each group member can understand the code of other group members, so as to facilitate the secondary development of source code memory system maintenance.
2. General format specifications
2.1 Indentation
Indentation is the two spaces exposed to increase readability when the level of the source program changes. The rule of indentation is to indent two spaces for each level. Tab is not allowed. Because Tab will produce different effects due to different settings made by the user. When you encounter begin or enter judgment, loop, exception handling, with statement, record type declaration, class declaration, etc., add one level. When you encounter end or exit judgment, loop, exception handling, with statement, record type declaration, Class declarations, etc. will be reduced by one level. For example:
ifTmpInt<>100then
TmpInt:=100;
2.2Begin..End
The begin statement and the end statement should occupy a single line in the source program, for example:
forI:=0to10dobegin//Incorrect usage
end;
forI:=0to10do//Correct usage
Begin
end;
2.3 Spaces
Add spaces at both ends of operators and logical judgment symbols, such as: I:=I+1;, aandb, etc., but no spaces are needed when adding brackets. For example: if(a>b)then//Incorrect usage
If(a>b)then//Correct usage
For example: PRocedureTest(Param1:integer;Param3:string);
3.ObjectPascal grammar writing format specifications
3.1 Reserved words
All reserved words or keywords in ObjectPascal should be used in lowercase letters.
3.2 Processes and functions
3.2.1 Naming and Format
The names of procedures and functions should all be composed of meaningful words, and the first letter of all words should be in capital letters. For example:
procedureformatarddisk;//Incorrect naming
procedureFormatHardDisk;// Correct naming
The process and function that sets the content of a variable should use Set as the prefix, for example:
procedureSetUserName;
Processes and functions that read variable content should use Get as prefix, for example:
functionGetUserName:string;
3.2.2 Parameters of procedures and functions
3.2.2.1 Naming
Parameters of the unified type are written in the same sentence:
procedureFoo(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 repetitive, add a prefix 'A', for example:
procedureSomeProc(AUserName:string;AUserAge:integer);
3.2.2.3 Naming Conflict
When the two units used include a duplicate function or procedure, when you refer to this function or procedure, the function or procedure in the unit declared in the use clause will be executed. To avoid such 'uses-clause-dependent', it is necessary to write the complete function or process source when referring to a function or process. For example:
SysUtils.FindClose(SR);
Windows.FindClose(Handle);
3.3 Variables
3.3.1 Variable Naming and Format
First of all variables must be given meaningful names so that other group members can easily understand the meaning represented by the variable. Variable naming can be synonymous with English name, and 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, for some specific types, certain abbreviations can be used 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. In addition, using a meaningful name such as UserIndex is also allowed.
3.3.2 Local variables
Using local variables in the process 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 prefix 'g', and the type of the variable should be reflected in the variable name. For example:
gprecUserCount:point;//The global variable with the name UserCount, its type is a pointer to a structure
But global variables can be used inside the module. All global variables in modules must be prefixed with 'F'. If data exchange is required between several modules, it needs to be implemented by declaring attributes. For example:
type
TFormOverdraftReturn=class(TForm)
Private
{Privatedeclarations}
FuserName:string;
FuserCount:Integer;
ProcedureSetUserName(Value:string);
FunctionGetUserName:string;
public
{Publicdeclarations}
propertyUserName: stringreadGetUserNamewriteSetUserName;
propertyUserCount:IntegerreadFuserCountwriteFuserCount;
end;
Type 3.4
3.4.1 Case protocol
The type names of reserved characters must be all lowercase. The Win32API types are usually all capitalized, and the first letters are capitalized for other types, and the remaining letters are lowercase, for example:
var
MyString:string;//reservedWord
WindowHandle:HWND;//Win32APItype
I:Integer;//typeidentifierintroducedinSystemunit
3.4.2 Floating point type
Try not to use the Real type, it just wants to be compatible with the old Pascal code and try to use the Double type. The Double type is an optimized processor and data bus and is a standard data structure defined by IEEE. Extended is used when the value is outside the range of Double. But Extended is not supported by Jave. However, the Single type may be used when writing DLLs in other languages.
3.4.3 Enumeration Type
The name of the enumeration type must be meaningful and the name of the type must be prefixed 'T'. The name of the content of the enum type must contain the abbreviation of the enum type name, for example:
TSongType=(stRock, stClassical, stCountry, stAlternative, stHeavyMetal, stRB);
3.4.4 Array Type
The name of the array type must be meaningful and the name of the type must be prefixed 'T'. If you declare a pointer to an array type, you must prefix 'P' before the name of that type, for example:
type
PCycleArray=^TCycleArray;
TCycleArray=array[1..100] ofinteger;
3.4.5 Record Type
The name of the record type must be meaningful and the name of the type must be prefixed 'T'. If you declare a pointer to an array type, you must prefix 'P' before the name of that type, for example:
type
PEmployee=^TEmployee;
TEmployee=record
EmployeeName:string
EmployeeRate:Double;
end;
Category 3.5
3.5.1 Naming and Format
The name of the class must be meaningful and the name of the type must be prefixed 'T'. For example:
type
TCustomer=class(TObject)
The name of a class instance is usually the name of the class with 'T' removed. For example:
var
Customer:TCustomer;
Variables in Class 3.5.2
3.5.2.1 Naming and Format
The name of the class must be meaningful and the name of the type must be prefixed 'F'. All variables must be four-in-one. If you need to access this variable from the outside, you need to declare a property
Method 3.5.3
3.5.3.1 Naming and Format
Naming and formatting of functions and procedures.
3.5.3.2 Attribute access method
All attribute access methods must appear in private or protected. Naming the attribute access method is the same as naming the functions and procedures. In addition, the readermethod must use the prefix 'Get'. The writermethod must use the prefix 'Set'. The parameter of the method written must be named 'Value', and its type is consistent with the attribute to be written. For example:
TSomeClass=class(TObject)
Private
fsomeField:Integer;
protected
functionGetSomeField:Integer;
procedureSetSomeField(Value:Integer);
public
propertySomeField:IntegerreadGetSomeFieldwriteSetSomeField;
end;
3.6 Properties
3.6.1 Naming and Format
The names of the variables of the class with the prefix 'F' are consistent with the operation.
3.7 File
3.7.1 Project File
3.7.1.1 Project directory structure
Program home directory --Bin (path where the application is located)
-Db (path where the local database is located)
-Doc (path where the document is located)
-Hlp (path where the help file is located)
-Backup (backup path)
-Tmp (temporary file path)
3.7.1.2 Naming
The project file must use a meaningful name. For example: The project file for system information in Delphi is named SysInfo.dpr.
3.7.2Form file
3.7.2.1 Naming
Consistent with the name of Form: For example: if the name of Form is FormMain, then the name of the Form file is FormMain.frm.
3.7.3DataModule file
3.7.3.1 Naming
The naming of the datamodule file should make sense and use 'DM' as the prefix. For example: the user datamodule is named 'DMCustomers.dfm'.
3.7.4RemoteDataModule file
3.7.4.1 Naming
The naming of the remotedatamodule file should make sense and use 'RDM' as the prefix. For example: the user remotedatamodule is named 'RDMCustomers.dfm'.
3.7.5Unit file
3.7.5.1 Normal Unit
3.7.5.1.1Unit file naming
The naming of the unit file should make sense and use 'unit' as the prefix. For example: a generic unit is named 'UnitGeneral'.
3.7.5.2FormUnits
3.7.5.2.1 Naming
The name of the Formunit file must be consistent with the name of the Form. For example: the main form is called FormMain.pas, the name of the FormUnit file is: UnitFormMain.
3.7.5.3DataModuleUnits
3.7.5.3.1 Naming
The name of the DataModuleunit file must be consistent with the name of the DataModule. For example: the main DataModule is called DMMain.pas, then the name of the DataModuleUnit file is: UnitDMMain.
3.7.5.4 File header
The purpose, author, date and input and output of this file should be written at the header of all files. For example:
{
Date of modification:
author:
use:
This module structure consists of:
}
3.7.6Forms and DataModulesForms
3.7.6.1Form class
1.Form class naming standards
The name of the Forms class should make sense and use 'TForm' as the prefix. For example: The name of the AboutForm class is:
TAboutForm=class(TForm)
The name of the main form is
TMainForm=class(TForm)
2. Naming standards for Form class instances
The names of Form class instances should be consistent with the names of Form class with 'T' during the same period. For example:
TypeName
InstanceName
TaaboutForm
AboutForm
TmainForm
MainForm
TCustomerEntryForm
CustomerEntryForm
3.7.6.2DataModulesForm
3.7.6.2.1.DataModuleForm Naming Standard
The naming of the DataModulesForms class should make sense and use 'TDM' as the prefix. For example:
TDMCustomer=class(TDataModule)
TDMOrders=class(TDataModule)
3.7.6.2.2.DataModule instance naming standard
The name of the DataModuleForm class instance should be the same as the name of the DataModuleForm class with 'T' drops at the same time. For example:
TypeName
InstanceName
TCustomerDataModule
CustomerDataModule
TordersDataModule
OrdersDataModule
3.8 Controls
3.8.1 Naming of control instances
An instance of a control should use the name of the control class that removes 'T' as a prefix, for example:
The name of the Tedit that enters the user's name is: EditUserName.
3.8.2 Abbreviation of controls
The name of the control can be used with the following abbreviation, but the abbreviation used is added between the control name '_':
3.8.2.1StandardTab
mmTMainMenu
pmTPopupMenu
mmiTMainMenuItem
pmiTPopupMenuItem
lblTLabel
edtTEdit
memTMemo
btnTButton
cbTCheckBox
rbTRadioButton
lbTListBox
cbTComboBox
scbTScrollBar
gbTGroupBox
rgTRadioGroup
pnlTPanel
clTCommandList
3.8.2.2AdditionalTab
bbtnTBitBtn
sbTSpeedButton
meTMaskEdit
sgTStringGrid
dgTDrawGrid
imgTImage
shpTShape
bvlTBevel
sbxTScrollBox
clbTCheckListbox
splTSplitter
stxTStaticText
chtTChart
3.8.2.3Win32Tab
tbcTabControl
pgcTPageControl
ilTImageList
reTRichEdit
tbrTTracBar
prbTProgressBar
udTUpDown
hkTHotKey
aniTAnimate
dtpTDateTimePicker
tvTreeView
lvTListView
hdrTHeaderControl
stbTStatusBar
tlbTToolBar
clbTCoolBar
3.8.2.4SystemTab
tmTTimer
pbTPaintBox
mpTMediaPlayer
olecTOleContainer
ddccTDDEClientConv
ddciTDDEClientItem
ddscTDDEServerConv
ddsiTDDEServerItem
3.8.2.5 InternetTab
cskTClientSocket
sskTServerSocket
wbdTWebDispatcher
ppTPageProducer
tpTQueryTableProducer
dstpTDataSetTableProducer
nmdtTNMDayTime
necTNMEcho
nfTNMFinger
nftpTNMFtp
nhttpTNMHttp
nMsgTNMMsg
nmsgTNMMSGServ
nntpTNMNNTP
npopTNMPop3
nuupTNMUUProcessor
smtpTNMSMTP
nstTNMStrm
nsTNMStrmServ
ntmTNMTime
nudpTNMUdp
pskTPowerSock
ngsTNMGeneralServer
htmlTHtml
urlTNMUrl
smlTSimpleMail
3.8.2.6DataaccessTab
dsTDataSource
tblTTable
qryTQuery
spTStoredProc
dbTDataBase
ssnTsession
bmTBatchMove
usqlTUpdateSQL
3.8.2.7DataControlsTab
dbgTDBGrid
dbnTDBNavigator
dbtTDBText
dbeTDBEdit
dbmTDBMemo
dbiTDBImage
dblbTDBListBox
dbcbTDBComboBox
dbchTDBCheckBox
dbrgTDBRadioGroup
dbllTDBLookupListBox
dblcTDBLookupComboBox
dbreTDBRichEdit
dbcgTDBCtrlGrid
dbchTDBChart
3.8.2.8DecisionCubeTab
dcbTDecisionCube
dcqTDecisionQuery
dcsTDecisionSource
dcpTDecisionPivot
dcgTDecisionGrid
dcgrTDecisionGraph
3.8.2.9QReportTab
qrTQuickReport
qrsdTQRSubDetail
qrbTQRBand
qrcbTQRChildBand
qrgTQRGroup
qrlTQRLabel
qrtTQRText
qreTQREexpr
qrsTQRSysData
qrmTQRMemo
qrrrtTQRRichText
qrdrTQRDBRichText
qrshTQRShape
qriTQRImage
qrdiTQRDBMImage
qrcrTQRCompositeReport
qrpTQRPreview
qrchTQRChart
3.8.2.10DialogsTab
OpenDialogTOpenDialog
SaveDialogTSaveDialog
OpenPictureDialogTOpenPictureDialog
SavePictureDialogTSavePictureDialog
FontDialogTFontDialog
ColorDialogTColorDialog
PrintDialogTPrintDialog
PrinterSetupDialogTPrintSetupDialog
FindDialogTFindDialog
ReplaceDialogTReplaceDialog
3.8.2.11Win31Tab
dbllTDBLookupList
dblcTDBLookupCombo
tsTTabSet
olTOutline
tnbTTabbedNoteBook
nbTNoteBook
hdrTHeader
flbTFileListBox
dlbTDirectoryListBox
dcbTDriveComboBox
fcbTFilterComboBox
3.8.2.12SamplesTab
ggTGauge
cgTColorGrid
spbTSpinButton
speTSpinEdit
dolTDirectoryOutline
calTCalendar
ibeaTIBEventAlerter
3.8.2.13ActiveXTab
cfxTChartFX
vspTVSSpell
f1bTF1Book
vtcTVTChart
grpTGraph
3.8.2.14MidasTab
prvTProvider
cdsTClientDataSet
qcdsTQueryClientDataSet
dcomTDCOMConnection
oleeTOleEnterpriseConnection
sckTSocketConnection
rmsTRemoteServer
midTmidasConnection
4. Modify the specifications
The provisions made in these rules apply only to procedures that have been incorporated into configuration management. In such modifications, it is required to retain the content before the modification and identify the modified and newly added content. And add necessary information such as modifyer, modification date, modification instructions, etc. to the file header.
4.1 Modify the history record
When making approved modifications to the source file, the modifyer should add a modification history item to the program file header. In each subsequent modification, the modifyer must fill in the following information in the item:
Modify
Modification time
Reason for modification
How to modify the instructions
4.2 Add new code line
The new code line should have commented lines before and after.
//Modify person, modification time, modification instructions
Added line of code
//End of modification
4.3 Delete the code line
Use comment lines to describe before and after deleting the code line.
//Modify person, modification time, modification instructions
//The line of code to be deleted (comment the statement to be deleted)
//End of modification
4.4 Modify the code line
Modify the code line to delete the code line and add new code lines.
//Modify person, modification time, modification instructions
//The line of code before modification
//End of modification
//Modified code line
Modified line of code
//End of modification