Delphi code creation form specification The purpose of this specification: to give your code a unified and standard appearance, enhance
Readability, understandability, maintainability
Principle of this specification: Name reflects meaning, form reflects structure
1. Unit style
2. Style of each district
3. Statement style
4. Naming rules
Reference: Borland official Object Pascal style guide
Delphi5 Programmer's Guide to Coding Standards
{ }
{project name}
{ }
{Copyright (C) 2000,2001 Company Name}
{ }
{****************************************************** ******}
unit UnitName;
{****************************************************** ******
project:
Module:
describe:
Version:
date:
author:
renew:
TODO:
*************************************************** *****}
interface
uses
----,----,----,----,----,----,----,----,----,----, ----,
----,----, ----,----,----,----;
const
------------------;
------------------;
------------------;
type
------------------;
------------------;
------------------;
------------------;
------------------;
------------------;
var
------------------;
------------------;
------------------;
implementation
uses
----,----,----,----;
{$R *.RES}
{$R *.DFM}
--------------------------------;
--------------------------------;
--------------------------------;
--------------------------------;
--------------------------------;
--------------------------------;
--------------------------------;
--------------------------------;
--------------------------------;
--------------------------------;
--------------------------------;
--------------------------------;
end.return
Topic comments, purpose description of function procedures, statement comments
Blank lines: Copyright blocks, between classes, between methods -- (two lines) Internal blocks of methods (one line)
Space: used to enhance clarity
Indent: two spaces
----- = ----;
----- = ----;
----- = ----;
----- = ----;Extension
Prefix: as few as C_---; as many as one prefix per topic
Const
{ Topic 1 }
C_--- = ----; {meaning}
C_--- = ----; {meaning}
C_--- = ----; {meaning}
C_--- = ----; {meaning}
{ Topic 2 }
----- = ----;
----- = ----;
----- = ----;
----- = ----; Resource string, placed after the variable area
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),
(1, 0, 0),
(0, -1, 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');
T---- = ---------
Object type-->Entity that is stateful and provides services
T---- = class(----)
PRivate
--------
--------
protected
--------
--------
public
--------
--------
published
--------
--------
end; Sort alphabeticallyPrivate
1. All data is placed in the Private area, starting with F
2. The method pointers corresponding to all event attributes are placed in the Private area, starting with F.
3. The Get and Set methods of attributes are placed in the Private area --> are not prepared to be inherited.
4. The method to respond to the message is placed in the Private area.
protected
1. Methods and attributes that are called by subclasses but cannot be called by the outside world
2. Methods for subclasses to overload virtual; virtual; abstract
public
1. Build a destructor method
2. Methods for external calls
3. Attributes for external calls
published
1. Properties that appear in the Object Inspector for design use
2. An example of event response that appears in the Object Inspector for design time: TGIFVersion = (gvUnknown, gv87a, gv89a);
TGIFVersionRec = array[0..2] of char;
PInterfaceTable = ^TInterfaceTable;
TInterfaceTable = packed record
EntryCount: Integer;
Entries: array[0..9999] of TInterfaceEntry;
{ forWord declaration }
TGIFImage = class;
TGIFSubImage = class;
{--------------------------
TGIFItem
--------------------------}
TGIFItem = class(TPersistent)
private
FGIFImage: TGIFImage;
.............
end;
Be careful not to have default class object variables, declare them in the caller!
var
-----------: -------;
-----------: -------;
example:
GIFDelayExp: integer = 10; { Delay multiplier in mS.}
GIFDelayExp: integer = 12;
theme
-------------------------------------------------- --------}
{Purpose of method}
procedure ----------------------------
begin
--------;
--------;
end;
{Purpose of method}
function-----------------------------
begin
--------;
--------;
end;
Format return