码迷,mamicode.com
首页 > 其他好文 > 详细

函数和过程的参数

时间:2014-11-02 22:32:51      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   os   for   sp   div   

函数和 过程的参数有:

1.常量参数,如 function addFun( const x,y:integer):integer; 函数里面的x,y的值不能改变

function addFun( const x,y:integer):integer;
begin
  //x := x+1;  //x,y在函数里面不能赋值,因为x,y为const;
  result := x+y;
end;

2.形式参数,如 function addFun( x,y:integer):integer; 函数里面的x,y值可以改变,并且和实參的值不同

function addFun( x,y:integer):integer; 
begin
    x := x+1;    //x可以变化,和实參的x是2个不同的值;
    result := x+y;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
    a,b:integer;
begin
    a:=100;
    b:=99;
    showmessage ( intToStr(addFun(a,b)) ); out 200 //其中a,b可以放具体的值,这里是和变量参数不同的地方一,
    showmessage ( intTostr(a) );  //a out 100//说明a的值没有改变,还是原来的值这也是和变量参数不同的地方二;
end;

 

3.变量参数,如 function addFun( var x,y:integer):integer;

 

function addFun( var x,y:integer):integer; 
begin
    x := x+1;    //x可以变化,和实參的x是2个不同的值;
    result := x+y;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
    a,b:integer;
begin
    a:=100;
    b:=99;
    showmessage ( intToStr(addFun(a,b)) ); out 200 //只能是变量,不能是实参;
    showmessage ( intTostr(a) );  //a out 101            //a的值已经改变;
end;

 

 

函数和过程的参数

标签:style   blog   io   color   ar   os   for   sp   div   

原文地址:http://www.cnblogs.com/delphiclub/p/4070026.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!