unit SumPlus;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm5 = class(TForm)
lbl1: TLabel;
edt1: TEdit;
lbl2: TLabel;
edt2: TEdit;
lbl3: TLabel;
edt3: TEdit;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
function GetSum(A: Integer) : Integer; //获取从0到A之间所有整数和
function GetSumPlus(A: Integer; B: Integer): Integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
procedure TForm5.btn1Click(Sender: TObject);
var
x: Integer;
y: Integer;
z : Integer;
begin
x := StrToInt(edt1.text);
y := StrToInt(edt2.Text);
//z := StrToInt(edt3.Text);
z:= GetSumPlus(x, y); //调用SumPlus函数
edt3.Text := IntToStr(z);
end;
function TForm5.GetSum(A: Integer) : Integer; //获取0到A之间所有整数和
var
i : Integer;
sum : Integer;
begin
sum := 0;
for i := 0 to A do
sum := sum + i;
result := sum;
end;
function TForm5.GetSumPlus(A: Integer; B: Integer) : Integer;
begin
Result := GetSum(A) + GetSum(B) ; //嵌套调用函数
end;
end.
|