[delphi]参数带有默认值的函数

//带默认值的参数只能在后面
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 @ 2010-06-28 16:18  huhu0013  阅读(12241)  评论(0编辑  收藏  举报