传值、传址
procedure Tform1.myproc1(i: string); //传值
begin
i:= 'A' ;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x: string;
begin
x:= edit1.Text;
myproc1(x); //x只过来报信,把2送来,无变化
edit2.Text:= x; //结果为:2
end;
procedure Tform1.myproc2(var i: string); //传址
begin
i:= 'A' ; //变量替换
end;
procedure TForm1.Button2Click(Sender: TObject);
var
x: string;
begin
x:= edit1.Text;
myproc2(x); //x过来报信且住了一宿,变化了
edit3.Text:= x; //结果为:A
end;
procedure tform1.myproc3(const i: string); //const
begin
i:= 'A' ; //const为常量,常量不能赋值常量
end;
function tform1.GetNum1(i: integer):integer; //传值
begin
i:=i+10;
result:=i;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x,y:integer;
begin
x:=20;
y:=GetNum1(x); //x只过来报信,把2送来,无变化
edit1.Text:= inttostr(x);
edit2.Text:= inttostr(y);
end;
function tform1.GetNum2(var i: integer):integer; //传址
begin
i:=i+10;
result:=i;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x,y:integer;
begin
x:=20;
y:=GetNum2(x); //x过来报信且住了一宿,变化了
edit1.Text:= inttostr(x);
edit2.Text:= inttostr(y);
end;
默认参数
function getsum(x:integer=20;y:integer=30;z:integer=40):integer;
begin
result:=x+y+z;
end;
procedure TForm1.Button1Click(Sender:TObject);
var
iSum:integer;
begin
iSum:=getsum;∥结果为90,这时x、y、z均取的默认值
iSum:=getsum(10):/结果为80,这时y、z取的默认值
iSum:=getsum(10,20);∥结果为70,这时z取的默认值
iSum:=getsum(10,20,30);/结果为60
end;
标签:begin,end,Text,传值,var,integer,procedure
From: https://www.cnblogs.com/DQ-MINE/p/17132796.html