3.5 Type
3.5.1 Understanding
If the name of the name is a reserved word, then it should be written. Win32 API types are usually all capitalized and you must follow the agreement of the detailed type name in Windows.PAS or other API units. For other variable names, one letter should be uppercase, and other letters should be missed. Here are some examples:
VAR
MyString: String; // Reserved word
WindowHandle: hwnd; // Win32 API type
I: integer; // Type identifier introduced in the System unit
3.5.1.1 Floating point pointer type
Real types are not recommended because it exists just to compatibility with early Pascal code. In normal cases, use Double to implement the needs of floating point pointers. And, Double is optimized for the processor and bus, and it is also the standard data format defined in the IEEE. Extended is only used when the range is required to exceed the range defined by Double. Extended is the type of Intel definition and does not support in Java. Single is only used when the actual byte size of the floating point pointer variable has its meaning. (, For example, when using another language DLLS).
3.5.1.2 Enumeration Type
The name of the enumeration type needs to be in accordance with the purpose of this type. This type of name needs to be prefixed in character T to indicate that this is a type. The identifier list in the enumeration type must contain two or three characters to correspond to the name of the enumerated type - for example:
TsongType = (Strock, StClassical, StCountry, Stalternative, Stheavymetal, STRB);
The name of an instance of an enumeration type should be the same as the enumeration type of not prefix, unless there is a better reason to give this variable more special name, such as FavoritesongType1, FavoritesongType2, etc.
3.5.1.3 Variables and OLE variable types
Variables and OLE variable types are usually not recommended. However, this type must be used in programs that only have time to know the data type, which appears in COM and database development. OLE variables are used in COM-based programming, such as automation and ActiveX control, and variables are used in non-COM programming, because variables can store local Delphi strings (same as the same string variable) in the same variable, but The OLE variable converts all strings to an OLE string (WideChar string) and does not instance - they will be copied forever.
3.5.2 Structure Type
3.5.2.1 Array Type
The name of the array type needs to meet the purpose of use. The name of this type must be prefix T. If the array type pointer is required, then the pointer needs to be prefixed and should be immediately declared in front of the array declaration. E.g:
Type
PcycleArray = ^ TcycleArray;
TcycleArray = array [1 ... 100] of integer;
In practical applications, the name of the variable instance of the array should be its type of name to remove the prefix T.
3.5.2.2 Recording Type
The name of the record type should meet the purpose of using them. Its type of statement should be prefix T. If you want to declare the pointer of the record type, it should be prefixed and should close to the previous declaration of the type declaration. E.g:
Type
PEMPLOYEE = ^ Temployee;
Temployee = Record
Employeename: String;
Employeeerate: Double;
END;
3.6 statement
3.6.1 IF statement
The most frequently occurred behavior in the IF / THEN / ELSE statement is placed in the Then clause, while other behaviors that have less likely to be placed in the ELSE clause. Try to avoid using nested IF statements, using multiple IF statements in this case to judge various possibilities.
Do not use the IF nested more than five depths. The code should be written clearer and clear.
Do not use unnecessary parentheses in the IF statement.
If there are multiple conditions in the IF statement to be tested, these conditions should be arranged from left to right from left to right by less than a few order. Doing so allows the compiler to get the shortcut of Boolerance when compiling code, making your code best optimization. For example, if the condition 1 is fast through condition 2, the condition 2 is faster 3, then the arrangement in the IF statement should be:
IF Condition 1 And Conditions 2 and Conditions 3 THEN
3.6.2 CASE statement
3.6.2.1 General Topics
Each independent unit in a CASE statement should be arranged in a number or alphabetical order.
The action behavior of each CASE unit should be simple and should not exceed four to five lines. If the action you want is too complex, a separate process or function should be used.
The else clause in the CASE statement is only used when the default behavior is required or handled.
3.6.2.2 Format
The CASE statement should follow other structural division and naming conventions.
3.6.3 WHILE statement
In a While statement, it is not recommended to use the EXIT procedure to jump out of the loop, try to use only cyclic conditions to jump out of the loop.
The initialization code used in a While cycle should close to the WHILE cycle, not being separated by other unrelated statements.
Any end process should be carried out immediately after the loop.
3.6.4 for statement
The FOR statement can only replace the While statement when the number of cycles is known.
3.6.5 REPEAT statement
The REPEAT statement is the same as the While statement and follows the same general policy.
3.6.6 With statement
3.6.6.1 General Topics
The WITH statement should save use and have a lot of warnings. Avoid excessive use of the with statement and use multiple objects, records, and more in the WITH statement. E.g:
With record1, record2 do
These things will make programmers feel confused and difficult to find problems.
3.6.6.2 format
The WITH statement follows the format rules for naming conventions and minibo indicated by this document.
3.7 Structure abnormal processing
3.7.1 General Topics
Abnormal processing is used in large quantities of error correction and resource protection. That is to say that once the resource is assigned, a try ... finally must use to ensure that the resource is released correctly. This anomalous protection also refers to the allocation and release of resources in a unit's Initialization / Finalization or an object's constructor / design.
3.7.2 Try ... Finally used
In any case, every assignment should follow a try ... finally. For example, the following code will cause possible errors:
SomeClass1: = TsomeClass.create;
Someclass2; = tsomeclass.create;
Try
{do some code}
Finally
Someclass1.free;
Someclass2.free;
END;
A more secure and more appropriate allocation process should be:
SomeClass1: = TsomeClass.create;
Try
SomeClass2: = TsomeClass.create;
Try
{do some code}
Finally
Someclass2.free;
END;
Finally
Someclass1.free;
END;
3.7.3 Try ... Except
Only use try ... excepts when they are triggered and you want to perform some tasks. Usually, you don't have to use the Try ... Except statement in order to display an error message simply on the screen, because this will be automatically executed by the Application object. If you want to call the default exception handler after performing some tasks in the Except clause, use Raise to re-trigger an exception to the next handle. 3.7.4 Try ... Except ... Else
The else clause in Try ... Except is not recommended because it interrupts all exceptions including those you are not prepared.
3.8 type type
3.8.1 Names and format
The name of the class type should meet the purpose of using them. Type names should be prefixed to indicate that this is a type of definition - for example:
Type
TCUSTOMER = Class (TOBJECT)
The type of instance is usually the name of the type without prefix T - for example:
VAR
Customer: tcustom;
Note: Check the "Naming Standard of Component Type" to get more information about the component named.
3.8.2 domain
3.8.2.1 Named / Format
The domain name of the class follows the same agreed with the variable identifier, except that they should be prefixed in F, indicating that this is the name of a domain.
3.8.2.2 Visualization
All domains must be private. Want to access the domain outside the class to use attributes.
3.8.3 Method
3.8.3.1 Named / Format
The naming of the method should follow the procedures and functions of this document.
3.8.3.2 Use Static Method
If a static method is used, then this method cannot be inherited by the descendum of the class.
3.8.3.3 Using Virtual / Dynamic Method
If you intend to use the method of this class, you can use the virtual method if you are inherited by the proceedings. A dynamic method is only used when the method has multiple inherits (direct or indirect). For example, a class type contains a can inherit, and 100 descendants should inherit this method, then this method dynamically generates the memory used by 100 descendants.
3.8.3.4 Using Abstract Methods
If you use an abstract method in a class, this class cannot be created. Only use abstract methods in classes that never be created.
3.8.3.5 Property Access Method
All access classes can only appear in the Private or Protaced section of the class. Naming of attribute access methods should follow the process and function's agreed rules. Read Access Method (Method Reader) must be prefixed with a word GET. Writing Access Method (Method Writer) must be prefixed in word Set. Method The name of the parameter of the writer should be Value, and its type should be the type of attribute it operate. E.g:
TsomeClass = Class (TOBJECT)
Private
Fsomefield: integer;
protected
Function GetSomefield: integer;
Procedure setsomefield (value: integer);
public
Property Somefield: Integer Read Getsomefield Write Setsomefield;
END;
3.8.4 Property
3.8.4.1 Named / Format
The attribute If it is an accesser representing a private domain, then its name should be the name of the domain they operate to remove the explanatory F.
The name of the attribute should be a noun, not a verb. The attribute is indicated by data, and the method is represented by behavior.
The name of the array type should be a plural. In general, the name of the attribute should be singular.
3.8.4.2 Methods Using Access
Although there is no requirement, it is recommended to use a write access method as possible as possible for a private domain attribute.