PASSWORD 's Blog

用耳朵去聆听,用心来感受

用户操作
[即时聊天] [发私信] [加为好友]
彭为ID:libra01
58705次访问,排名1812好友0人,关注者0
libra01的文章
原创 63 篇
翻译 0 篇
转载 4 篇
评论 65 篇
彭为的公告

网名:PASSWORLD
QQ:3569555
MSN:pwzyp#msn.com
现工作在上海
最近评论
mldstk:wow power leveling
zhangjiajun1982:建议你看看这篇文章对你会有帮助的 http://www.150it.cn/bianchengwendang/VC/865064948.html
lovevirus:持之以恒,这是最重要的,谢谢主人的金玉良言,呵呵,郁闷时期给我一点鼓舞
dugang:兄弟,钱多的好找,不累的难找
骆归:楼主还行,但我想没有这么难,不想多说,帮你顶.
文章分类
收藏
    相册
    爱的足迹
    博客图片
    丑男形象
    Delphi
    ★卢培培★
    Angus Johnson's Delphi Components
    CrazyCock专栏
    flier_lu(有价值的文章)
    Think in Patterns 中文
    午夜听风的代码人生
    抉择不悔's blog
    梁甫吟
    超强的Delphi Tips
    风中之歌
    友情链接
    ===天地弦===
    DigJim 的博客(RSS)
    E步·软件资讯
    hkbarton-delphi
    为艺术为技术(RSS)
    孙辉的BLOG
    张硕(CathyEagle)的BLOG
    成片的大树
    我的另外一个生活博客
    编程手札(RSS)
    (RSS)
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创  代码创建形式规范 1.0 (for delphi) shunzimm [原作] 收藏

    新一篇:   对程序员职业的思考 | 旧一篇: 通用存储过程.查找删除非唯一的记录

    本规范的目的:给自己的代码一个统一而标准的外观,增强可读性,可理解性,可维护性
    本规范的原则:名称反映含义,形式反映结构

    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打头

     

    http://dev.csdn.net/article/31/31698.shtm

    发表于 @ 2004年07月30日 13:06:00|评论(loading...)|编辑

    新一篇:   对程序员职业的思考 | 旧一篇: 通用存储过程.查找删除非唯一的记录

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © 彭为