首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

新手:小实验有关问题,求解惑

2013-08-10 
新手:小实验问题,求解惑。unit Unit1interfaceusesWindows, Messages, SysUtils, Variants, Classes, Grap

新手:小实验问题,求解惑。
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
   function sum(i,j:integer):integer;
   begin
   //showmessage('yes!');
   j:=j+i;
   showmessage(inttostr(j));
  //Result j;
   end;
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
//var k:integer;
begin
    //k:=sum(3);
    showmessage(inttostr(sum(2,9)));
end;

end.
上面这段代码,我只是想实现一个自定义函数,并返回和。
但是我在Button1里调用,得到的结果是9.于是我怀疑是函数问题,是不是没有计算呢?
所以我在sum里show了一个j,弹出了一个空。说明运行了的,并且此时答案是11,结果正确!,后面还跟个对话框,一串数字。
是不是返回有问题?但是我使用result一直报错,我也不知道哪儿错了。求解答: 函数 对话框
[解决办法]
 function sum(i,j:integer):integer;
   begin
   //showmessage('yes!');
   //j:=j+i;
   showmessage(inttostr(j));
  //Result j;
    Result := j + i;//直接这一句就可以了
   end;

热点排行