深入方法[29] - 傳址參數不能賦予常量
{給這個函數可以賦常數變量}
{測試}
function Fun1(x,y: Integer): Integer;
begin
Result := x + y;
end;
{這個函數不能賦予常數變量}
function Fun2(var x,y: Integer): Integer;
begin
Result := x + y;
end;procedure TForm1.Button1Click(Sender: TObject);
var
i,a,b: Integer;
const
j = 6;
k = 8;
begin
i := Fun1(1,2);
ShowMessage(IntToStr(i)); {3}
//i := Fun2(1,2); {這樣是 Fun2 是錯誤的, 它的參數是傳地址的, 必須用變量}
//i := Fun2(j,k); {這樣也不行}
{應該:}
a := 2;
b := 4;
i := Fun2(a,b);
ShowMessage(IntToStr(i)); {6}
end;