我的程序中先动态生了一系列的edit控件,最后动态生成了一个button控件,button控件的事件与edit 控件有关,具体程序如下
a_credit:array[1..15] of tedit;
a_postbut:tbutton;
begin
a_credit[i]:=Tedit.create(self);
a_credit[i].Left:=..
a_credit[i].Text:='';
a_credit[i].Width:=40;
a_postbut:=Tbutton.Create(self);
a_postbut.Width:=150;
a_credit[i].Parent:=yuejuan;
a_postbut.Parent:=yuejuan;
a_postbut.OnClick:=a_postbutclick;
end;
对于 procedure a_postbutclick(sender:tobject)
过程是求出所有edit中的数字并求和,我想问的是这一个过程是否要声明?放在哪个位置好?我原来就是放在动态生成的过程中即在a_postbut.onclick:=a_postbutclick的后面了,但是好像不对。那应放在哪儿?如是放在动态生成控件过程的外面的话,那咱样传参数呢?

解决方案 »

  1.   

    最好声明一下
    放到那都可以
    _postbut.OnClick:=a_postbutclick;
      

  2.   


    我也是这样想的呀,放在a_postbut.onclick:=a_postbutclick;的后面也行吗?但是每次都要报错:statement expected but 'procedure'found 好像是不应该放在这儿呀。
      

  3.   

    type
      TForm1 = class(TForm)
       ..............
      private
        { Private declarations }
      public
        { Public declarations }
        procedure aClick(Sender: TObject);
      end;...........
    Button2.OnClick := Form1.aClick;
      

  4.   

    procedure a_postbutclick(Sender: TObject)//Add
    begin                                    //Add     
    //寫你要寫的                             //Add
    end;                                     //Add
    var                                      //Add 
    a_credit:array[1..15] of tedit;
    a_postbut:tbutton;
    begin
    a_credit[i]:=Tedit.create(self);
    a_credit[i].Left:=..
    a_credit[i].Text:='';
    a_credit[i].Width:=40;
    a_postbut:=Tbutton.Create(self);
    a_postbut.Width:=150;
    a_credit[i].Parent:=yuejuan;
    a_postbut.Parent:=yuejuan;
    a_postbut.OnClick:=a_postbutclick;
    end;
    yansea的也是一種很好的方法。一般的都是這么寫的﹐我寫的就是當這個procedure與全局沒有關系時﹐就可以這么寫。
      

  5.   

    to yukin2003
    那个a_postbutclick事件也是可以写在动态生成控件的过程中?好的我试一试,有问题再头号你们了,谢谢哟:)
      

  6.   

    你试着按ctrl+shift+c看看!系统会自动帮你声明的!
    有问题请发信息到我的E-mail:[email protected]
      

  7.   

    我试过了必须把这个过程的声明放在动态生成控件的窗体的type说明中,然后这个过程的定义必须在动态生成控件过程之外的一个单独过程才行。但是我程序设计中在a_postbutclick事件中要求用到在动态生成控件过程中的edit的值,如放在外面的话那就得有一个参数传递问题,这咱处理呢?
      

  8.   

    搞不清楚你要作什么最好说的清楚一些,看不明白,或者我的理解能力比较差?......不过是不是可以这样?type
      TForm1 = class(TForm)
       ..............
      private
        { Private declarations }
      public
        { Public declarations }
        a_credit:array[1..15] of tedit;
        procedure aClick(Sender: TObject);
      end;procedure form1.aClick()...
    var
      i : integer;
    begin
      //判断a_credit是否创建
      for i :=0 to 15
      .....end;