• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi初浅入门笔记之三:过程和函数(过程篇)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

过程:

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.

源代码下载


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Matlab DIP(瓦)ch4图像频域滤波练习发布时间:2022-07-18
下一篇:
matlab在2维区域内生成不重叠的多个圆形发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap