下面是整个的代码,我加的代码已经注释了。unit Unit1;interfaceuses
  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 he(a :integer;b:integer):integer;   //我加的
begin   //我加的    
he := a * b;   //我加的
end;   //我加的
procedure TForm1.Button1Click(Sender: TObject);
begin   
edit3.Text:= inttostr(he(strtoint(edit1.text),strtoint(edit2.text)))   //我加的
end;end.
[Error] Unit1.pas(31): Undeclared identifier: 'edit3'
[Error] Unit1.pas(31): Undeclared identifier: 'edit1'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
错误该怎么改呢?    听说少了edit3.Text这个控件,不知道是不是?    能帮我编译一下就最好了啊!我只在form中创建了一个button,然后把代码加入。      

解决方案 »

  1.   

    问题:
    1:function he(a :integer;b:integer):integer;没有声明
       且定义函数时该是
       function TForm1.he(a :integer;b:integer):integer;
    2:自定义函数中没有返回值,
        可以是:result he;而且he没有定义
    3:‘我只在form中创建了一个button,然后把代码加入。’
       难道你edit1, edit2,edit3也没加吗?
      

  2.   

    1、首先保证你的界面上有 Edit1、Edit2、Edit3、Button12、下面是代码:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}function he(a :Integer; b:Integer):Integer;
    begin
      Result := a * b;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Edit3.Text := IntToStr(he(StrToInt(Edit1.Text),StrToInt(Edit2.Text)));
    end;end.
      

  3.   

    1.函数要先声明再定义。2.delphi分过程(procedure)和函数(function),函数有返回值,并且返回值delphi有个固定的用法  Result := '数值';3.当你程序中用的vcl组件的时候,要么再设计期就拖上去,要么在程序中动态创建
      

  4.   

    下面的这些是什么?动态创建吗?      不是的话动态创建又是什么?  百度了一下还不是很清楚。Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
      

  5.   

    我按照3楼给的代码可以编译,   但是有些我还不是很懂,
    function TForm1.he(a :integer;b:integer):integer;
     1楼你给的这个函数定义我加入代码中了,可是不能编译,   下面是代码。
    要把 Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
    加入后才可以,    可是直接按3楼的代码就可以了啊,  这样声明、定义function不是多余了吗?  不解?unit Unit1;interface    uses    
       Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,    Dialogs, StdCtrls;    type    
     TForm1 = class(TForm)
     Button1: TButton; procedure Button1Click(Sender: TObject);
     function he(a :Integer; b:Integer):integer;
    private      
    { Private declarations }    
    public
    { Public declarations }    end;    var    Form1: TForm1;    implementation{$R *.dfm}    function TForm1.he(a :Integer;b:Integer):integer;begin
    Result := a * b;
    end;procedure TForm1.Button1Click(Sender: TObject);begin
    Edit3.Text := IntToStr(he(StrToInt(Edit1.Text),StrToInt(Edit2.Text)));
    end;end.
      

  6.   

    先声明再实现和直接在implementation
    区域写是有区别的
    关于函数/过程的声明你可以看看 万一老师 的Delphi博客