分享
 
 
 

代码创建形式规范 1.0 (for delphi)

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

本规范的目的:给自己的代码一个统一而标准的外观,增强可读性,可理解性,可维护性

本规范的原则:名称反映含义,形式反映结构

1、单元风格

2、各区风格

3、语句风格

4、命名规则

参考:borland官方object pascal风格指南

delphi5程序员指南编码标准

1、单元风格

{*******************************************************}

{ }

{ 项目名称 }

{ }

{ 版权所有 (c) 2000,2001 公司名称 }

{ }

{*******************************************************}

unit unitname;

{*******************************************************

项目:

模块:

描述:

版本:

日期:

作者:

更新:

todo:

*******************************************************}

interface

uses

----,----,----,----,----,----,----,----,----,----,----,

----,----, ----,----,----,----;

const

--------------------;

--------------------;

--------------------;

type

--------------------;

--------------------;

--------------------;

--------------------;

--------------------;

--------------------;

var

--------------------;

--------------------;

--------------------;

implementation

uses

----,----,----,----;

{$r *.res}

{$r *.dfm}

--------------------------------;

--------------------------------;

--------------------------------;

--------------------------------;

--------------------------------;

--------------------------------;

--------------------------------;

--------------------------------;

--------------------------------;

--------------------------------;

--------------------------------;

--------------------------------;

end.

返回

2、各区风格

0、注释与空白

用{ } 不用 //

主题注释,函数过程目的说明,语句注释

空行 :版权块,类之间,方法之间--(两行) 方法内部块(一行)

空格 :用以增强清晰度

缩进 :两个空格

1、常量区

基本:

const

----- = ----;

----- = ----;

----- = ----;

----- = ----;

扩展

前缀: 少则c_---;多则可以每个主题有一个前缀

const

{ 主题1 }

c_--- = ----; { 含义 }

c_--- = ----; { 含义 }

c_--- = ----; { 含义 }

c_--- = ----; { 含义 }

{ 主题2 }

----- = ----;

----- = ----;

----- = ----;

----- = ----;

资源字符串,放在变量区后面

resourcestring

const

s_--- = '----';

s_--- = '----';

s_--- = '----';

例子:

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');

2、类型区

数据类型-->不提供服务的数据类型

t---- = ---------

对象类型-->有状态并提供服务的实体

t---- = class(----)

private

--------

--------

protected

--------

--------

public

--------

--------

published

--------

--------

end;

按字母排序

private

1、所有数据放在private 区,以f打头

2、所有事件属性对应的方法指针放在private 区,以f打头

3、属性的get与set方法放在private 区-->不准备被继承

4、响应消息的方法放在private 区

protected

1、被子类调用的但不能被外界调用的方法与属性

2、供子类重载的方法 virsual; virsual; abstract

public

1、构建析构方法

2、供外界调用的方法

3、供外界调用的属性

published

1、出现在object inspector里供设计时用的属性

2、出现在object inspector里供设计时用的事件响应

例子:

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;

.............

end;

3、变量区

定义全局变量

注意不要有缺省的类对象变量,在调用者中声明!

var

-----------: -------;

-----------: -------;

例子:

gifdelayexp: integer = 10; { delay multiplier in ms.}

gifdelayexp: integer = 12;

4、实现区

{---------------------------------------------------------

主题

----------------------------------------------------------}

{ 方法的目的 }

procedure ----------------------------

begin

--------;

--------;

end;

{ 方法的目的 }

function -----------------------------

begin

--------;

--------;

end;

5、过程与函数

命名

格式

返回

3、语句风格

1、简单语句

-------;

2、复合语句

begin

-----;

-----;

end;

3、赋值语句

-- := -------;

-- := (-- + --)* (-- / --);

4、局部变量

var

---: ---;

---: ---;

对于逻辑上并列的变量组:

var

---,

---,

---: ---;

5、数组声明

--- = array [*..*] of ---;

6、if 语句

if (--------) then

-------------;

if (--------) then

begin

-------------;

-------------;

-------------;

end;

if (--------) then

-------------;

else

-------------;

if (--------) then

begin

-------------;

-------------;

-------------;

end else

-------------;

if (--------) then

begin

-------------;

-------------;

-------------;

end else

begin

-------------;

-------------;

-------------;

end;

if (--------) then

-------------

else if (--------) then

-------------;

7、for 循环

for i := -------- to -------- do

-------------;

for i := -------- to -------- do

begin

-------------;

-------------;

-------------;

end;

for i := -------- to -------- do

if (--------) then

begin

-------------;

-------------;

-------------;

end;

for i := -------- to -------- do

with -------- then

begin

-------------;

-------------;

-------------;

end;

8、while 循环

while ------ do

begin

-------------;

-------------;

-------------;

end;

9、repeat 循环

repeat

-------------;

-------------;

-------------;

until ------;

10、case 语句

case -------- of

-------- : -------------;

-------- : -------------;

-------- : -------------;

else -------------;

end;

case -------- of

-------- :

-----------------------------------------------------------------;

-------- :

-----------------------------------------------------------------;

-------- :

-----------------------------------------------------------------;

else

-----------------------------------------------------------------;

end;

case -------- of

-------- : begin

--------------------------;

--------------------------;

--------------------------;

end;

-------- : begin

--------------------------;

--------------------------;

--------------------------;

end;

-------- : begin

--------------------------;

--------------------------;

--------------------------;

end

else begin

-------------;

-------------;

-------------;

end;

end;

11、with 语句

with -------- do

-------------;

with -------- do

begin

-------------;

-------------;

-------------;

end;

12、try 语句

try

-------------;

-------------;

-------------;

finally

-------------;

-------------;

-------------;

end;

try

try

-------------;

-------------;

-------------;

except

-------------;

-------------;

end;

finally

-------------;

-------------;

-------------;

end;

13、其它

运算:运算符前后要有空格

w1[n] := ((i + 1) * v0[n] + j * v1[n] + (k - 1) * v2[n]) / depth;

-- = --

-- >= --

-- <= --

-- > --

-- < --

-- <> --

-- := --; 赋值

--: ----; 类型

同一类型且含义逻辑上不并列的变量 20个字符长的变量名

private

------- : -------;

------- : -------;

------- : -------;

------- : -------;

------- : -------;

var

------- : -------;

------- : -------;

------- : -------;

------- : -------;

------- : -------;

function ---------------------(--: ----; --: ----; --: ----): ----;

同一类型且含义逻辑上并列的变量 如 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 after create}

destructor destroy; override; {if need to do something before destroy}

function --------------: -------;

procedure --------------;

property -------: ------- read f-------;

published

end;

14、形式反映结构

例子:

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('inappropriate 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;

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、命名规则

1、文件名称: u模块名称;见名知意

2、控件名称: 功能_控件缩写;见名知意

3、变量 : 尽量不用缩写,尽量用名词;见名知意

4、方法与过程:尽量不用缩写,尽量用动宾词组;见名知意

5、常见的惯例

类名以t打头 (type之意)

类的私有数据域以f打头(field之意)

对数据的存取操作分别以set,get打头

事件属性以on打头

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有