过程:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{
在这里定义了两个过程:CalcFact,GetSum。过程CalcFact(Num:Integer;Var value:Int64)需要传入一个Integer类型的参数,然后通过形参Value来将值返回。由此可以知道,过程的定义是以Procedure关键字开头的,然后是过程的名字 然后是参数列表后面还需要一个”;”。
}
procedure CalcFact(Num:Integer;Var value:Int64);
var
i:Integer;
begin
Value:=1;
for i:=1 to Num do
Value:=Value*i;
end;
procedure GetSum(V1,V2:Integer;Var Sum:Int64);
var
SumV1,SumV2:Int64;
begin
CalcFact(V1,SumV1);//在这里调用了CalcFact这个过程
CalcFact(V2,SumV2);
Sum:=SumV1+SumV2;
end;
procedure TForm1.Button1Click(Sender: TObject);
Var
Sum:Int64;
Ed1,Ed2:Integer;
begin
if(edit1.Text='') or (edit2.Text='') then
begin
Application.MessageBox('请输入整数','提示:',MB_OK);
exit;
end;
Ed1:=StrToInt(edit1.Text);
Ed2:=StrToInt(edit2.Text);
GetSum(Ed1,Ed2,Sum);
label1.Caption:=trim(edit1.Text)+'与'+trim(edit2.Text)+'的阶乘和为'+IntToStr(Sum);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
end.