Source Code Code Specification ANGUS

zhaozj2021-02-16  54

Source code code specification

I. General

1.1 Purpose To properly standardize the programmer's development, this specification is specially formulated. Its fundamental purpose is to ensure that the program has a good, consistent structure, in order to improve the program's readability and maintainability, facilitate the process of testing, maintenance, upgrade, etc., and also cultivate programmers writing code normative .

1.2 The principle name reflects the meaning, the form reflects the structure;

1.3 Affirmation This specification is applicable to all companies that use Delphi development tools. The programmer should be strictly prepared according to this specification. If the project has a special special requirement, it must also be reviewed by the project manager, the special requirements form a document. Save the attached file of the document.

1.4 Documentation: Xue Guoshun first revised on June 23, 2001: Xue Guoshun second revision on July 7, 2001: Xue Guoshun September 28, 2001

Ii. Code Specification

2.1 Project Specifications

2..1.1. Each item's code, the document, according to the module, function must be stored in the project folder, each item must be included in each project folder: Code: Source Code SQL: Database script directory Demodata: Demo Directory UserData: User Directory Help: Help Document Directory Install: Installation Directory Document: Document Directory Picture: Photo Directory Templates: Report Template catalog subfolder must also establish subdirectory in detail. Detailed examples are as follows:

Example:

Project Name | Code SQL DEMODATA PICTURE HELP Install Document Templates | | App Server Client || Test Document Design Document Data Dictionary Demand Analysis User Document Module1 Module2 Module3 ......

2..1.2. There must be a project description file in the main directory of each project, indicating some of the profiles and related specifications.

2..1.3. There must be a folder documentation in each subdirectory under the project folder, describing the classification methods and meaning of the layer folder and its subfolders. At any time, when adding a folder, you must add the category of the new folder in the folder document in the same directory, and create the folder documentation below this folder.

2.1.4. Engineering file code specification: a. Any project file (including dynamic link library engineering file) must be described in the form of an annotation, the company copyright, engineering description, version description, creation date, authors, and subsequent updates. B. In addition to the main module, public function module, and public data modules, all units under this project cannot be automatically created by the project. After the new unit is added, the automatic Create statement must be removed in the project file. C. The remaining code of the project documents follow the unit specifications and other code specifications of this document;

2.2 Overall Specification of Unit

2.2.1 The first part of each unit must explain the project name in the form of an annotation, the company copyright; 2.2.2 must explain the item name, module name, module description, module version, creation date after the form is followed by the unit name , Author, update, todo list;

2.2.3 In principle, the unit of the interface section is only allowed to add Delphi's IDE automatically. If you need to add yourself, you must add a reason after reference to the cell name. The pseudo command used to compile switch control is inserted before use.

2.2.4 The Interface section should contain only the types, variables, processes, and functions that need to be accessed by external units, and these declarations should be before the IMPLEmentation section.

2.2.5 The Implementation section contains the types, variables, procedures, and functions of this unit.

2.2.6 Unless there is indeed, do not write over multi-code in the Initialization section, if you have code, you should write a detailed note, you must write the reason for the Initialization section.

2.2.7 Release all resources allocated in the initialization section in the Finalization section.

2.2.8 Except for the master FORM, each form unit should contain an instantiation function (inlet function), used to create, set, display, and release Form. The Form variable should be removed from the unit, and the modified function is changed as a local variable (to be moved from the automatic generation list of the Project Options dialog). (See 2.1.4.B)

2.2.9 Overall Stylistics Rule: Two spaces are maintained at each stage. Do not store the "Tab" symbol to the source file because "Tab" characters will have different definitions in different source code management. Do not select the Set Tab Character and Optimal Fill check box in Tools | Editor Options, which will not be saved. Marked page width: The margin should maintain 80 characters of the default setting, as long as it is possible, the statement that exceeds a line must be wrapped in a comma or operator. After the wrap, the two characters should be indensed. Note Rules: Use // only when the end of the row of rows, otherwise you must use {} to comment. Dark line use: There is an empty line where there is: the copyright block, class, method process function, method internal algorithm segmentation. The blank line can only be used in one line, and the extra blank line must be deleted. Begin ... END: Under any circumstances, BeGin and End must have their own exclusive lines. The sum of the sum of the corresponding Begin left alignment. Tools Use: All units are submitted to the version control tool must be formatted with Source Code Formatter.

Example:

{********************************************************** ******} {} {project name} {} {copyright (C) 2000, 2001 Company Name} {} {******************************* *****************************************

Unit unitname; {************************************************************* ********* project: module: description: version: date: author: update: TODO: ************************* *****************************}

Interface

{$ I is.inc}

Uses -, ----, ----, ----, ----, ----, ---- , ----, ----;

Const --------------------; Type ------------------; var ----- ---------------;

IMPLEMENTATION

Uses -, ----, ----, ----;

{$ R * .res} {$ r * .dfm}

--------------------------------------------------- ----------------------------------------------;

End.

2.3 internal specifications

2.3.1 Confirmation Zone: A. The first prefix of all constants must be c, constant must be divided into class definitions, if there are multiple topics, each subject must add a topic prefix. Between the prefix and the prefix, the prefix is ​​used between _ segmentation. B. The definition of each constant is a row, on the same row, the meaning of the constant must be used with //. C. The first line of categorization at the topic must use the {} annotent meaning in the first line of each subject.

D, example:

Const

{Topic 1} C_ Topic Prefix 1_--- = ----; // Meaning C_ Top Prefix 1 _--- = ----; // Meaning C_ Top Prefix 1_--- = --- -; // meaning c_ subject prefix 1 _--- = ----; // meaning {topic 2} c_ subject prefix 2 _-- = ----; // meaning c_ subject prefix 2 _---- - = ----; // meaning c_ subject prefix 2 _--- = ----; // meaning c_ subject prefix 2 _--- = ----; // meaning

2.3.2 Type: A. Data types that do not provide services are: T ---- = --------- // Type Meaning B, stateful and provide service data type definition format : T ---- = Class (----) // Type Meaning Private -------- Protected -------- PUBLIC -------- Publish ---- ---- End; C, in principle, data type and its internal method, attribute, data definition should be arranged in alphabetical order. The read and write methods of the attribute are named GET and SET, respectively. D, internal data, attribute, method definition rules: D1, Private area 1, all data is placed in the Private area, with F head. 2. The method of all event attributes corresponds to the PRIVATE area and heads with F. 3. The GET and SET methods that are not ready to be inherited are placed in the Private area. 4. The method of responding to the message is placed in the Private area. D2, Protected area 1, the method and properties of the quilt-in-quilt call but cannot be called by the outside world. 2. Method for overloading the child. VIRSUAL ;VIRSUAL; D3, PUBLIC zone 1, constructing a destructive method 2 for external calling method 3 for external calling attributes D4, PublisHED zone 1, appears attributes used in Object Inspector 2, appearing in Object Inspector for design Event response E, special data should be used in the line of defining a row to note. Special properties should be annotated in the definition of the {} annotation. The definition of the event pointer does not require a comment, but the event type must be used in the previous line to note its meaning in the previous line. 2.3.3 Variable Area A, global variables of the variable zone definition unit. B. Each variable that needs to be annotated separately, with // to comment on the line with //. C, the same type and the meaning logically unlaminated variables are defined, the same type and the meaning logical variables are defined together. D, generally do not encourage global variables. When you do need to use global variables, global variables must be limited to the desired environment, such as: a global variable may only be globally located in units of the unit, so it must be defined in this section. The global data used by multiple units should be moved into a common module. E, global variables can be directly initialized to a certain value when defined. Note: All global variables will be automatically initialized, so do not initialize global variables as null values, such as 0, nil, '', unassigned. Zero initialization global variables do not take up space in executable files, and non-zero-initialized global variables are spaced in executable files. F, naming rules for variables See the naming rules items behind this document.

2.3.4 Implementing zone A, events, procedures, and functions should be collected together according to topic classification, and the first row of each subject is used to annotate the topic. The appointment classification method is as follows: The event of the same component should be collected, and the function or process of the relationship between the event call or associated with the relationship, the function, the process, the process, and the method should also be invoked. Collect together unless the function is called multiple. The internal function of the unit called multiplely, the process should be detrued within the public process theme of the unit. Customized categorization methods can be customized, such as categorizing functionality, but if the categorization method is different from this agreement, the classification method should be used before all topics. B, each event, method must be used in its code before its code, description, parameter meanings, creation time, author, update person, update time, update time. In an event, a different sense of algorithm or different topics within an event, a different topic, and the beginning of each algorithm or the initial start with the purpose of {} annotation algorithm or theme. The key algorithm should be used in the end of the line. Events, the variables within the method are defined, and the variable area specification conventions agreed is required. C, SQL statement writing rules: In the SQL statement, all SQL reserved words unified use of uppercase, all field names, and data table names all with lowercase, select, from, where, order by the top, each clause requires each clause. Fields or each condition or each association is individually hoped. And indented alignment, indent in two classes. Examples are as follows: strMastersql: = 'select preload. *,' ​​ 'Codelib.codename vesselname' 'BLSTATUS = Case Blstusid when "1" The "Booking"' 'When "2" THEN "with route"' ' ELSE "Other" ' ' end; ' ' from preload ' ' left codelib.codecd = preload.vesselcd ' ' and cotelib.classid = "03" '; strMasterfilter: =' Where preloadad .companycd =: companyCD ' ' and preload.idno =: idno '; strMasterOrder: =' Order by preloadNo '; Note: Case ... When ... Then ... Else ... End statement is different. D, the location of the database field name is used in the code, and use lowercase. E, the properties of the component itself, the event name, and must be written according to the format of the Delphi automatic prompt. 2.4 Object Pascal Syntax Convention

2.4.1 Syntax Miscellaneous: A. There must be one space before and after the operator. B, in the starting parentheses and the latter character, and the end parentheses and the last characters do not have spaces. Do not appear unnecessary parentheses in the statement. If IF (i = 42) THEN, parentheses is unnecessary. C, the reserved word and keywords for Object Pascal language are always lowercase. D. It is generally not recommended to use Variant and Olevariant, unless the data type can only be determined or known during the runtime. Olevariant is often used for COM-based programs: AUUTOMATION and ACTIVEX control, Variant Based on non-COM program. E. If the REAL type is not available in the code, the Double type should be used for floating point numbers. F. When defining object features, you should use a read / write method to access. 2.4.2 Process and Function A, the order of the metallin Mainly considers the register call rule, the most commonly used parameters should be used as the first parameter, follow the left to right. The input parameters should be located before the output parameter. The large-scale parameters should be placed before the range of small parameters, such as the event handle that is automatically generated by someProc (ACOUNTRY, ASTATE, ATITY) IDE, and the parameter order does not have to be contemplated. B, all constant parameters should be marked with a Const tag. C. To avoid naming conflicts, in addition to the routine of the public module, call other modules, the functionality of the routine should be added to the unit name where the routine is added to the routine. D, unless it is indeed initialized before use, the internal variable of the routine should be initialized immediately at the entrance of the routine. 2.4.3 Specification A, IF statement: In the IF / THEN / ELSE statement, the most likely executed should be placed in the THEN clause, which may be smaller in the ELSE clause. Try to avoid using a continuous IF statement, you should use the CASE statement instead. Do not nescery the IF statement of the 5 floors. Do not use excess parentheses in the IF statement. If there are multiple conditions in the IF statement, the conditions should be neatly arranged from left to right from the left to right from the fastest to the slowest computing. Specifications for IF statements: IF (--------) THEN -------------;

IF (--------) THEN BEGIN -------------; -------------;

IF (--------) THEN ------------- Else -------------;

IF (--------) THEN BEGIN -------------; -------------; Else ------- ------;

IF (--------) THEN BEGIN -------------; -------------; Else Begin -------------------------------------------------------------------------- -------; -------------;

IF (--------) ------------- Else IF (--------) THEN ------------ -; B, CASE statement: In the case statement, constant of each case should be arranged in a number or alphabetical order. The action statement corresponding to each case should be short and usually no more than 4-5 lines. If the action is too complex, the code should be placed in a separate process or function. The ELSE clause of the CASE statement is only used for default or error detection. Case statement specification example: case -----------------------------; --------: -----------; --------: -------------; Else -------------; End; cas -------- of ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------: ---- -------------------------------------------------- -----------; ---------------------------------------------------------------------------------- ----------------------------------------------------------------------- -------------------------------------------------- ---;

Case -------- Of --------: Begin --------------------------; --- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ; END; --------: Begin -------------------------------------- ------------------------------------------; End; ----: Begin ------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------; ELSE BEGIN ---------- ---; -------------; -------------; End; end; c, while statement: Do not use the exit process to jump out of a while loop . If necessary, you should use the loop condition to exit the loop. All code initialized for the While loop should be in front of the WHILE port and do not be separated by unrelated statements. Description of the While statement: while ------ do begin -------------; -------------; ------- ----; end; d, for statement: If the number of cycles is determined, use the for statement to replace the While statement. Specifications for the for statement: for i: = -------- To -------- do -------------; for i: = ---- ---- To -------- Do Begin ---------------------------; ------- ------;

For i: = -------- To -------- DO if (--------) THEN Begin -------------; ------------; -------------;

For i: = -------- To -------- do with ----------------------; --- ----------; -------------; End; E, REPEAT statement: Repeat statement and while statement is similar, and follow the same rules. Sample example of the specification of the REPEAT statement: REPEAT ------------------------------------; Until ------; f, with statement: with statement should be used as little as possible, especially with a number of objects of multiple objects. Description of the WITH statement: with -------- do -------------; with -------- do begin --------- ----; ------------; -------------; End; g, try statement: unless it is part of the unit's INITIZATION / FINALIZATION section or Allocation / Release Resources in the object's construction / sector, otherwise, all the use of resources must be used to ensure that the resources are released. In the case of possible, each resource allocation should be paired with a try ... finally structure. You cannot use the ELSE sentence in Try..Exception, as this is likely to hinder all other exceptions. It is necessary to perform some custom tasks when an exception is used, only use of try ... except, if only to display an error message, there is no need to use Try ... Except, because the Application object can automatically do this according to the context. If you want to activate the default abnormality in the Except clause, you can use RAISE to trigger an exception again. Try statement specification example: try -------------------------; -------------; Finally -------------; -------------;

Try Try --------------; -------------; Except ----- ---------------------------------------------------------------------------------; ---; -------------;

2.5 Name Specification

2.5.1 Process, Naming Rules for Functions. A, the routine name begins with uppercase letters, and should be capitalized at the first letter with different words. B, the routine name should make sense and should use the Babble phrase as much as possible. C, the routine name that sets the input parameter value should be prefixed with a set to its prefix, and the number of routines that get the value should be prefixed in GET. D. The shape of the routine should express its use, as long as it may, the name of the ginseng should be prefixed in letter A. E, Delphi's IDE automatically generated event handle, name, and parameters cannot be changed.

2.5.2 Variable Naming Rules A. The name of the variable should be able to express its use. Try not to abrupt, and use noun as a variable name. B, the variable name should be used as a prefix, such as StrmasterSQL. B. The loop control variable can be a single letter as i, j, k, or a meaningful name can also be used. C, the name of the Boolean variable must be clearly expressed in True and False. E, the global variable of the project should be prefixed as G_. The global variable in the unit should be prefixed as a U_. 2.5.3 Type, Class, Object Naming Rules A. Define Enumeration Types should be plus T as a prefix before name, and the prefix of the enumeration type identifier list should contain 2 to 3 lowercase characters to associate each other. Such as: TsongType = (Strock, StClassical, StCountry, Stalternative, StheavyMetal); a modem variable name of an enumeration type named Type Name Remove the prefix "T" unless you give this variable more meaningful names for a reason. B, the array type name should express the use of the array, and the type name must add the letter T as a prefix. If you want to declare a pointer to the array type, you must add the letter P as a prefix, and should be declared before the type declaration. Such as: type pcycleArray = ^ TcycleArray; tcyclearray = array [1..100] of integer; the array type variable named the type name to remove the prefix "T". C, the record type name should express the use of the record, and the type name must add the letter T as a prefix. If you want to declare a pointer to the type of record, you must add the letter P as a prefix, and should be declared before the type declaration. D, the name of the class must be the use of this class. Type names must start with character "T" indicating that he is a type definition. The instance name of the type is usually matched with the type name without the character "T". E, the private data field (Fields) naming rules are the same, but must add characters "f" in front. F, class method naming and process, the name of the function. G, the attribute name of the class should be a noun, not a verb. The naming rules of the property are the same as the private data field of the class, but do not add a F prefix. H, the event naming should be prefixed in ON, Before, After.

2.5.4 File Naming Specification A, Engineering Document: Engineering Documents should give meaningful names. You can take the full name of the project, or the uppercase of the start character of the word, or the abbreviation of each word. You can also naming a single word directly. B, Form file: The name of the form file must be able to express the use of Form and have an FRM prefix. C, data module file: The name of the Data Module file must be able to express the use of data modules and have a DM prefix. D, Remote Data Module File: The name of the Remote Data Module file must be used to express the use of remote data modules and have an RDM prefix. E, unit file: The unit file name of the form and data module should be the same as the corresponding Form and data module name. Naming of universal units (such as public function libraries, variable libraries, constant libraries, etc.) should try to express its meaning and use lib as a prefix.

2.5.5 Forms, Names Rules of Data Modules A, the name of the Form type should express the use of Form, and to add TFRM as a prefix, followed by the descriptive name. B, the name of the Form instance is the same as the corresponding type name, but there is no prefix T. C, the type name of the data module should be: prefix TDM descriptive name. D, the name of the data module instance is the same as the corresponding type name, but there is no prefix T. 2.5.6 Component Naming Rules A, component naming standards and class naming standards are similar. Different is that they have three characters of the iconic prefix, used to indicate companies, individuals, etc. Three characters as a prefix should be written. B, the registration unit name of the component should be added to the three character prefixes, the prefix is ​​the same. C, Component Instance Name Rules: Component Type Prefix Descriptive Name. D, the type of Delphi standard component is prefixed as follows: Standard Tab

mm TMainMenupm TPopupMenummi TMainMenuItempmi TPopupMenuItemlbl TLabeledt TEditmem TMemobtn TButtoncb TCheckBoxrb TRadioButtonlb TListBoxcb TComboBoxscb TScrollBargb TGroupBoxrg TRadioGrouppnl TPanelcl TCommandList

Additional Tab Bbtn TbitBtnsb TspeedButtonMe Tmaskeditsg TstringGriddg TshapeBVL Tbevelsbx TscrollboxClb TchecklistBoxspl Tsplitterstx TStaticTextCht Tchart

Win32 Tab tbc TTabControlpgc TPageControlil TImageListre TRichEdittbr TTrackBarprb TProgressBarud TUpDownhk THotKeyani TAnimatedtp TDateTimePickertv TTreeViewlv TListViewhdr THeaderControlstb TStatusBartlb TToolBarclb TCoolBar

System Tab Tm Ttimerpb TpaintBoxmp TmediaPlayerolec ToleContainerddcc TddeClientConvddci TddeClientItemDDSC TDDeServerConvddsi TDDeselItemItem

Internet Tab csk TClientSocketssk TServerSocketwbd TWebDispatcherpp TPageProducertp TQueryTableProducerdstp TDataSetTableProducernmdt TNMDayTimenec TNMEchonf TNMFingernftp TNMFtpnhttp TNMHttpnMsg TNMMsgnmsg TNMMSGServnntp TNMNNTPnpop TNMPop3nuup TNMUUProcessorsmtp TNMSMTPnst TNMStrmnsts TNMStrmServntm TNMTimenudp TNMUdppsk TPowerSockngs TNMGeneralServerhtml THtmlurl TNMUrlsml TSimpleMail

Data Access Tab ds TDataSourcetbl TTableqry TQuerysp TStoredProcdb TDataBasessn TSessionbm TBatchMoveusql TUpdateSQLData Controls Tab dbg TDBGriddbn TDBNavigatordbt TDBTextdbe TDBEditdbm TDBMemodbi TDBImagedblb TDBListBoxdbcb TDBComboBoxdbch TDBCheckBoxdbrg TDBRadioGroupdbll TDBLookupListBoxdblc TDBLookupComboBoxdbre TDBRichEditdbcg TDBCtrlGriddbch TDBChart

Decision Cube Tab DCB TDecisionCubedcq TdecisionQuerydcs TDecisionSourceDcp TDecisionPivotdcg TDecisionGriddcgr TDecisiongraph

QReport Tab qr TQuickReportqrsd TQRSubDetailqrb TQRBandqrcb TQRChildBandqrg TQRGroupqrl TQRLabelqrt TQRTextqre TQRExprqrs TQRSysDataqrm TQRMemoqrrt TQRRichTextqrdr TQRDBRichTextqrsh TQRShapeqri TQRImageqrdi TQRDBMImageqrcr TQRCompositeReportqrp TQRPreviewqrch TQRChart

Win31 Tab dbll TDBLookupListdblc TDBLookupCombots TTabSetol TOutlinetnb TTabbedNoteBooknb TNoteBookhdr THeaderflb TFileListBoxdlb TDirectoryListBoxdcb TDriveComboBoxfcb TFilterComboBox

Samples Tab GG Tgaugecg Tcolorgridspb TspinButtonspe Tspineditdol TdirectoryoutLineCal Tcalendaribea Tibeventalerter

ActiveX Tab CFX TCHARTFXVSP TVSSPELLF1B TF1BOOKVTC TVTCHARTGRP TGRAPH

Midas Tab PSP TdataSetProvidercds TclientDataSetdcom TdcomConnection Olee toleEnterpriseConnectionSck TsocketConnectionRMS TremoteSerVermid TMIDASCONNECTIONONNECTION

Ado Tab Adocn Adoconnection Adoccu Adocommandadods Adodatasetad Adotableadoq AdoQueryAdosp AdoStoreProCrdsc Rdsconnection

Interbase Tab ibt ibtableibq ibQueryibsp ibstoreProcibd ibdatabaseibts ibtransactionibu ibupdatesqlibds ibdatalectionibsql ibsqlibdi ibdatabaseInfoibsm ibsqlmonitoribe ibevents

III. Supplement

3.1 This document must be approved and approved by this document if there is an unknown place or needs to be modified.

3.2 Documents If there is any change, the change date and the change person should be indicated in 1.4.

转载请注明原文地址:https://www.9cbs.com/read-25128.html

New Post(0)