The purpose of this specification: gives the code, enhanced readability, understandability, and maintenance of this specification: name reflecting the structure
1, unit style 2, various district styles 3, statement style 4, naming rules
Reference: Borland Official Object Pascal Style Guide Delphi5 Programmer Guide Code Standard
1, unit style
{********************************************************** ******} {} {project name} {} {copyright (C) 2000, 2001 Company Name} {} {******************************* *****************************************
Unit unitname; {************************************************************* ********* project: module: description: version: date: author: update: todo: ************************* *****************************}
Interface
Uses -, ----, ----, ----, ----, ----, ---- , ----, ----, ----, ----, ----, ----, ----;
Const ------------------------------; ------- -------------; TYPE ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------; ----------------------------------------;
VAR --------------------------------------- -------------;
IMPLEMentation
Uses -, ----, ----, ----;
{$ r * .res} {$ r * .dfm}
--------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------; ----------------------------------------------------------------- -------------; --------------------------------; --- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------; --------------------------------;
End.
return
2, neutral style 0, annotation and blank use {} no // topic annotation, function process purpose, statement comment blank line: copyright block, class, method - (two lines) method internal block (one line) Space: Used to enhance clarity indent: two spaces 1, constant zone basic:
CONST ----- = ----; ----- = ----; ----- = ----;
Extended prefix: less c _---; Many, you can have a prefix const in each topic
{Topic 1} C _--- = ----; {Meaning} C _--- = ----; {Meaning} C _--- = ----; {Meaning} C_-- = - -; {Meaning} {Topic 2} ----- = ----; ----- = ----; ----- = ----; ----- = - ---;
Resource string, placed behind the variable zone
ResourceString
Const s _--- = '----'; s _--- = '----'; s _--- = '----';
example:
cm_base = $ b000; cm_activate = cm_base 0; cm_deactivate = cm_base 1; cm_gotfocus = cm_base 2; cm_lostfocus = cm_base 3; numpaletteentries = 20; boxpoints: array [0..5, 0..2] of glfloat = ((-1, 0, 0), (0, 1, 0), (0, 0), (0, 0, 0), (0, 0, 1), (0, 0, -1) ));
{Variant Type Codes (WTYPES.H)}
Varempty = 0000; {vt_empty} varnull = $ 0001; {vt_null} VARSMallint = $ 0002; {vt_i2} gifversions: array [gv87a "gifversions: array [gv87a..gv89a] of tgifversionRec = ('87a', '89a');
2, Type Area Data Type -> Data Type Type T ---- = --------- Object Type -> State and Service Type ---- = Class ----) Private -------------- - Protected -------------- PUBLIC -------- ------ Published -------- -------- End;
Private 1, all data is placed in the Private area, with F header 2, all event attributes correspond to the PRIVATE area, with F Head 3, the attribute GET and SET methods are placed in the Private area -> Not ready to be inherited 4 The method of responding to the message is placed in the Private area Protected 1, but the method of the quilt class is called, but cannot be called by the outside, the method 2, the supplied subsidiary overload method virsual; Virsual; AbstractPublic 1, build a sectoral method 2 for external calls Method 3, for external calling attributes Published 1, appears attribute 2 for design in Object Inspector, appears in Object Inspector for an event response
example:
tgifversion = (gvunknown, gv87a, gv89a); tgifversionrec = array [0..2] of char; pinterfacetable = ^ tinterfacetable; tinterfacetable = packed record entrycount: integer; entries: array [0..9999] of tinterfaceentry;
{ForWord Declairation} TGIFIMAGE = Class; TGIFSUBIMAGE = Class; {-------------------------- TGIFITEM ---------- ------------------} TGIFITEM = Class (TPERSIStent) private fgifimage: TGIFIMAGE; .............
3. Variable Area Definition Global Variable Notice Do not have default class object variables, declare in the caller! VAR -----------: -------; -----------: -------; example: gifdelayexp: integer = 10; { DELAY MULTIPLIER IN MS.} gifdelayexp: integer = 12;
4, realize the area {--------------------------------------------------------------------------------------------------------------------- ------------ Theme ------------------------------------- ---------------------}
{Method's purpose} procedure ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -;
{Method's destination} function ------------------------------------; ----- ---;
5, process and function naming format
return
3, statement style 1, simple statement -------; 2, composite statement begin -----; -----;
3, assignment statement -: = -------; -: = (- -) * (- / -); 4, local variable var ---: ---; -: ---; For variables of logical columns: var ---, ---, ---:
5, array declaration --- = array [*.. *] OF ---;
6, IF statement IF (--------) THEN -------------;
IF (--------) THEN BEGIN -------------; -------------; --------- ----;
IF (--------) THEN -------------; Else -------------;
IF (--------) THEN BEGIN -------------; -------------; --------- ----; ELSE -------------;
IF (--------) THEN BEGIN -------------; -------------; --------- ----; Else Begin --------------; -------------; END;
IF (--------) ------------- Else IF (--------) THEN ------------ -;
7, for cycle
For i: = -------- To -------- DO -------------;
For i: = -------- To -------- Do Begin --------------------------- ; -------------;
For i: = -------- To -------- DO if (--------) THEN Begin -------------; ------------; -------------;
For i: = -------- To -------- do with ----------------------; --- ----------; -------------;
8, WHILE cycle
While ------ Do Begin ---------------; ------------- ;
9, REPEAT loop repeat -------------; -------------; -------------; Until - ----;
10, CASE statement
Case -------- OF ------------------------------------------: ---------------------------------------------------------------------------------------------------------------------------- -----; --------: -------------; Else -------------;
Case -------- Of --------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------- ---------; ---------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------- -; End; cas -------- of --------: begin ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ; ----------------------------------------------------------------------------------------------------------------------------------------------- ----; End; --------: Begin --------------------------; ------ ------------------------------------------------; --------: Begin ------------------------------------------- -------------; --------------------------; END Else Begin -------------; -------------;
END;
11, WITH statement with ---------------------;
With -------- Do Begin -------------; ----------- -;
12, TRY statement try -------------; -------------; -------------; Finally - -----------; -------------; -------------;
Try Try --------------; -------------; Except ----- ---------------------------------------------------------------------------------; ---; -------------;
13, other operations: There must be space W1 before and after the operator [N]: = ((i 1) * v0 [n] j * v1 [n] (k - 1) * v2 [n]) / depth; - = - -> = - - <- - <> - -: = -; Assignment -: ----; Type
The same type and mean the logically unconcered variable 20 characters long variable name private -------: -------; -------: -------; -------: -------; -------: -------; -------: -------; var - ------: -------; -------: -------; -------: -------; ----: -------; -------: -------; Function ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -: ----; -: ----):
Same types and meanings logical variables such as Error0, Error1, Error2; R, G, B Private -------, -------, -----, ---- ---, -------: ------- Var -------, -------, -------, ------ -, -------: ------- Function --------------------- (-, -: -: ---; var -, -, -: ----):
T ------- = Class (------) Private F -------: -------; f -------: ---- ---; f -------: -------; function --------------: -------; Procedure ---- ----------; protected function --------------: -------; Procedure ------------- -; Function --------------: -------; virtual; abstract; public constructor create (-----: -------) Override; {if Need to do something attroy; override; {if Need to do something before design --------------: -------- Procedure --------------; Property -------: ------- Read F -------; PublisHed;
14, form reflecting the structure example: Tetindex: array [0..3] of tinteger3v = ((0, 1, 3), (2, 1, 0), (3, 2, 0), (1, 2, 3) ))); Cursors: array [0..4] of tidentmapenTry = ((value: crdefault; name: 'crdefault'), (Value: Crarrow; Name: 'Crarrow'), (Value: crcross; Name: 'crcross' ), (Value: cribeam; name: 'cribeam'));
if (dwflags and pfd_draw_to_window) = 0) or ((dwflags and pfd_support_opengl) = 0) or ((dwflags and pfd_doublebuffer) = 0) or (ipixeltype <> pfd_type_rgba) or (ccolorbits <16))) then raise exception.create ( 'INAPPRIATE PIXEL FORMAT Chosen.');
Glbegin (Shadetype); Glnormal3FV (@ n0); GlvertEX3FV (@dodec [a, 0]); GlvertEX3FV (@dodec [b, 0]); GLVERTEX3FV (@dodec [c, 0]); GLVERTEX3FV (@dodec [d) , 0]); GLVERTEX3FV (@dodec [e, 0]); glend ();
DODEC [0, 0]: = -alpha; DODEC [0, 1]: = 0; DODEC [0, 2]: = Beta; DODEC [1, 0]: = alpha; dodec [1, 1]: = 0 ; DODEC [1, 2]: = Beta; DODEC [2, 0]: = -1; DODEC [2, 1]: = -1; DODEC [2, 2]: = -1; Procedure Glutwiretorus (InnerRadius: gldouble ; // --------- OuterRadius: gldouble; // --------- nsides: glint; // --------- rings: glint); // - -------- Case Frundirection of Rdrighttoleft: Begin Sty: = CNY; StX: = Width - Currentstep; End; RdlexToright: Begin Sty: = CNY; stx: = - currentstep; end; rdbottomtotop: begin stx: = CNX; style: = height - currentstep; end; RDTOPTOBOTTO M: begin stx: = cnx; style = currentstep - rtHeight; End; Else Begin Stx: = CNX; STY: = CNY; END;
case (dithermode) of dmnearest: ditherer: = tditherengine.create (bitmap.width, colorlookup); dmfloydsteinberg: ditherer: = tfloydsteinbergditherer.create (bitmap.width, colorlookup); dmstucki: ditherer: = tstuckiditherer.create (bitmap.width, colorlookup); dmsierra: ditherer: = tsierraditherer.create (bitmap.width, colorlookup); dmjajuni: ditherer: = tjajuniditherer.create (bitmap.width, colorlookup); dmstevearche: ditherer: = tstevearcheditherer.create (bitmap.width, colorlookup) DMBURKES: DITHERER: = TburkesdithereR.create (Bitmap.width, ColorLookup); Else EXIT; END; return
4, Name Rules 1, File Name: U Module Name; See the name of the name: Features _ control abbreviation; see the name of the name 3, variable: Try not to abbreviate, try to use the noun; see the name of the name of 4, method With the process: try not to use abbreviation, try to use the PTI group; see the name of the name 5, the common practice class name with T head (Type "class, the private data field of the T-head (FIELD" is accessible to the data Operation is taking the set, GET header event attributes