打印本文 打印本文 关闭窗口 关闭窗口
Delphi代码的标准风格
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3677  更新时间:2009/4/23 18:40:47  文章录入:mintao  责任编辑:mintao
;
end;



//正确


if A = B then
begin
  DoSomething;
  DoSomethingElse;
end
else
begin
  DoThis;
  DoThat;
end;


    以下的少数变化可以被采用:
//正确


if Condition then
begin
  DoThis;
end else
begin
  DoThat;
end;




//正确


if Condition then
begin
  DoThis;
end
else
  DoSomething;




//正确


if Condition then
begin
  DoThis;
end else
  DoSoemthing;




//下面的方式可能不被关心,但却是值得赞扬的:


if Condition then
  DoThis
else DoThat;




8.2.4 for语句
Example:
// INCORRECT


  for i := 0 to 10 do begin
    DoSomething;
    DoSomethingElse;
  end;




// CORRECT


  for i := 0 to 10 do
  begin
    DoSomething;
    DoSomethingElse;
  end;




8.2.5 while 语句
Example:
// INCORRECT


  while x < j do begin
    DoSomething;
    DoSomethingElse;
  end;




// CORRECT


  while x < j do
  begin
    DoSomething;
    DoSomethingElse;
  end;




8.2.6 repeat until 语句
Example:
  // CORRECT


  repeat
    x := j;
    j := UpdateValue;
  until j = 25;




8.2.7 case 语句
Example:
// CORRECT


  case Control.Align of
    alLeft, alNone: NewRange := Max(NewRange, Position);
    alRight: Inc(AlignMargin, Control.Width);
  end;



  // CORRECT


  case x of
    csStart:
      begin
        j := UpdateValue;
      end;
    csBegin: x := j;
    csTimeOut:
      begin
        j := x;
        x := UpdateValue;
      end;
  end;


  // CORRECT


  case ScrollCode of
    SB_LINEUP, SB_LINEDOWN:
      begin
        Incr := FIncrement div FLineDiv;
        FinalIncr := FIncrement mod FLineDiv;
        Count := FLineDiv;
      end;
    SB_PAGEUP, SB_PAGEDOWN:
      begin
        Incr := FPageIncrement;
        FinalIncr := Incr mod FPageDiv;
        Incr := Incr div FPageDiv;
        Count := FPageDiv;
      end;
  else
    Count := 0;
    Incr := 0;
    FinalIncr := 0;
  end;





8.2.8 try 语句

// Correct


  try
    try
      EnumThreadWindows(CurrentTh

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口