{给这个函数可以赋常数变量}
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;

posted on 2008-01-15 15:52  万一  阅读(3931)  评论(1编辑  收藏  举报