5,379
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Double_A(Value:integer):Integer;//不允许缺参数调用、参数能被改变
begin
Value:=Value+10;
Result:=Value;
end;
function Double_B(var Value:integer):Integer;//不允许缺参数调用、参数必须是变量、参数能被改变
begin
Value:=Value+20;
Result:=Value;
end;
function Double_C(const Value:integer=30):Integer;//允许不带参数调用(无参数调用时,使用30作传入值)、参数不能被改变
begin
//Value:=Value+10;//因为参数是常量,因此不能赋值给Value
Result:=Value+30;
end;
function Double_D(const Value:integer):Integer;//不允许缺参数调用、参数不能被改变
begin
//Value:=Value+10;//因为参数是常量,因此不能赋值给Value
Result:=Value+40;
end;
procedure TForm1.Button1Click(Sender: TObject);
var x:integer;
begin
x:=10;
//Double_A 函数调用形式:
showmessage('Double_A函数(用常量作参数)传回的值是:'+inttostr(Double_A(10)));
showmessage('Double_A函数(用变量作参数)传回的值是:'+inttostr(Double_A(x)));
//showmessage('Double_A函数(无参数)传回的值是:'+inttostr(Double_A));//不能无参数
//Double_B 函数调用形式:
//showmessage('Double_B函数(用常量作参数)传回的值是:'+inttostr(Double_B(10)));//不能以常量作参数
showmessage('Double_B函数(用变量作参数)传回的值是:'+inttostr(Double_B(x)));
//showmessage('Double_B函数(无参数)传回的值是:'+inttostr(Double_B));//不能无参数
//Double_C 函数调用形式:
showmessage('Double_C函数(用常量作参数)传回的值是:'+inttostr(Double_C(10)));
showmessage('Double_C函数(用变量作参数)传回的值是:'+inttostr(Double_C(x)));
showmessage('Double_C函数(无参数)传回的值是:'+inttostr(Double_C));
//Double_D 函数调用形式:
showmessage('Double_D函数(用常量作参数)传回的值是:'+inttostr(Double_D(10)));
showmessage('Double_D函数(用变量作参数)传回的值是:'+inttostr(Double_D(x)));
//showmessage('Double_D函数(无参数)传回的值是:'+inttostr(Double_D));//不能无参数
end;
end.