Delphi source Program Format Writing specification (i) (2)

Source: Internet
Author: User

3.3 Variables

3.3.1 variable naming and formatting

First of all variables must have a meaningful name, so that other members can easily read the meaning of variables, variable naming can be synonymous with the English name, you can use a few English words, but the first letter of each word must be capitalized. For example: Var writeformat::string;

At the same time for some specific types can be used in a certain shorthand as follows:

Pointer type P
Record Type Rec
Array type ARR
Classes Class

loop control variables usually use a single word Furu: I, J, or K. In addition the use of a meaningful name for example: Userindex, is also permitted.

3.3.2 Local Variables

Use local variables in the procedure to follow the naming rules for all other variables.

3.3.3 Global Variables

Try not to use global variables, you must prefix ' g ' If you must use global variables, and you should reflect the type of the variable in the name of the variable. For example:
The gprecusercount:point;//name, called the UserCount global variable, is typed as a pointer to a struct, but can be used within the module with global variables. Global variables in all modules must be prefixed with ' F '. If data exchange is required between several modules, it needs to be implemented by declaring the property's method. 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 Types

3.4.1 Case Protocol

The type name of the reserved word must be all lowercase. The type of the Win32 API is typically all uppercase, and 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 type

Try not to use the real type, he's just trying to be compatible with the old Pascal code and try to use double type. The Double type is a standard data structure that is optimized for both the processor and the data bus and is IEEE-defined. Use extended when the value is outside the double range. But extended is not supported by Jave. However, a single type may be used when using DLLs written in other languages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.