随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

//带默认值的参数只能在后面
function MyFun(a:Integer; b:Integer=1; c:Integer=2): Integer;
begin
  Result := a + b + c;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  x: Integer;
begin
  x := MyFun(1);
  ShowMessage(IntToStr(x));  //4

  x := MyFun(1,2);
  ShowMessage(IntToStr(x));  //5

  x := MyFun(1,2,3);
  ShowMessage(IntToStr(x));  //6
end;

posted on 2007-12-06 17:23  万一  阅读(...)  评论(...编辑  收藏