Delphi code creation form specification

zhaozj2021-02-16  55

Delphi code creation form specification

The purpose of this specification: the principle of a uniform appearance, enhanced readability, understandability, and maintainability of this code: Name reflecting the structure

1, unit style 2, various zone style 3, statement style 4, naming rule reference: Borland official object Pascal style guide Delphi5 programmer guide coding standard

1, unit style

{********************************************************** ******} {} {project name} {} {copyright (C) 2000, 2001 Company Name} {} {******************************* *********************************} Unit unitname; {********** ******************************************** Project: Module: Description : version: date: author: update: TODO: *************************************** ***************} InterfaceUses ----, ----, ----, -, ----, ----, -, ----, ----, ----, ----, ----, ----, -; Const ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------; -------------------------------------------; ----------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -; ----------------------------; var ----- ------------------------------------- -------; ImplementationUses ----, ----, ----, ----; {$ r * .res} { $ R * .dfm} -----------------------------------------------; --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----; ------------------------------------------------------------------------------------------------------------------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---; ----------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -; ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------- -;

return

2, various people

0, annotation and blank

Use {} no // topic annotation, function process purpose description, statement comment blank line: copyright block, class, method - (two lines) method internal block (one line) space: to enhance clarity indentation : Two spaces 1, constant area

Basic:

CONST ----- = ----; ----- = ----; ----- = ----;

Extended prefix: less c _---; more, you can have a prefix const {topic 1} c _--- = ----; {meaning} c _--- = ----; {meaning} C_--- = ----; {Meaning} C_--- = ----; {Meaning} {Topic 2} ----- = ----; ----- = --- -; ----- = ----; ----- = ----;

Resource string, put it behind the variable zone ResourceStringConst 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..gv89a] of TGIFVersionRec = ( '87a' , '89a');

2, type area

Data Type -> Data Type T ---- = --------- Object Type -> State Type -> State Type ----- = Class (---- Private -------- -------- Protected ------------------------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Published -------------- END; sort by alphabet

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; ............. End;

3, variable area

Define global variables not to 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 ------------------------------------------------------------------------------------------------------ - Begin --------; --------; End; {method's purpose} function --------------------- -------- Begin --------; --------;

5, process and functions

Name format

return

3, statement style

1, simple statement -------; 2, composite statement begin -----; -----;

3, assignment statement -: = -------; -: = (- -) * (- / -); 4, local variable var ---: ---; -: ---; For variable groups logical: var ---, ---, ---: ---; 5, array statement --- = 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 i: = -------- To ---------------------;

For i: = -------- To -------- Do Begin --------------------------- ; -------------; End; for i: = -------- To -------- DO if (--------) THEN BEGIN -------------; -------------; -------------; end; for i: = -------- To -------- do with -----------------------; ------- -------------------;

8, WHILE cycle

While ------ Do Begin ---------------; ------------- ;

9, REPEAT loop repeat -------------; -------------; -------------; Until - ----;

10, CASE statement case ----------------: --------------------: ---- ---------; --------: -----------------; End; Case -------- Of --------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------- ---------; ---------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------- -; End; cas -------- of --------: begin ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ; ----------------------------------------------------------------------------------------------------------------------------------------------- ----; End; --------: Begin --------------------------; ------ ------------------------------------------------; --------: Begin ------------------------------------- ---; -----------------------------------------------; -----------; -------------; End;

11, with statement

With -------- Do -------------; with -------- Do Begin -------------; ------------; -------------;

12, TRY sentence

TRY -------------; -------------; Finally ------ -------; --------------; -------------;

Try Try --------------; -------------; Except ----- ---------------------------------------------------------------------------------; ---; -------------; End; 13, other

Operation: There must be space W1 before and after the operator [N]: = ((i 1) * v0 [n] j * v1 [n] (k - 1) * v2 [n]) / defth; - = - -> = - - -: = -; 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 --------------------- ({ifrride; {if narrow; {ifrride; {if need; {ifrride; {ion; } F Unction --------------: -------; Procedure --------------; Property -------: - ------ Read F -------; Published end; 14, the form reflects the structure

Example: TetIndex: Array [0..3] of Tinteger3V = ((0, 1, 3), (2, 1, 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 Frundirecti on of rdRightToLeft: begin StY: = CnY; StX: = Width - CurrentStep; end; rdLeftToRight: begin StY: = CnY; StX: = - CurrentStep; end; rdBottomToTop: begin StX: = CnX; StY: = Height - CurrentStep; End; rdtoptobottom: Begin Stx: ​​= CNX; Sty: = currentstep - rtHeiGHT;

end; else begin StX: = CnX; StY: = CnY; end; 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; 4, naming rules

1, file name

: U module name; see the name of the name 2, the control name

: Features _ control abbreviations; see the name of the name of 3, variables

: Try not to abbreviate, try to use noun; see the name of the name

4

, Method and Process: Try not to use abbreviations, try to use movement phrases; see the name of the name of 5, common practice class names with T head (Type "class with F Head (Field" to data Access operations are taking the set, Get header event at the end

(Finish)

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

New Post(0)