Code
//带默认值的参数只能在后面
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;
//带默认值的参数只能在后面
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;