在程序运行时,如何动态生成控件数组,控件数组已能创建,但不知如何响应事件??
程序中注释不知如何写才正常???unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure MyClick(Sender:TObject;index:integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
 var MB:array [0..5] of TEdit;
      i:integer;
      a:Tobject;
begin
 for i:=0 to 5 do
 begin
 mb[i]:=Tedit.Create (Self);
 mb[i].parent:=form1;
 mb[i].top:=100;
 mb[i].left:=100+i*150;
 //mb[i].OnClick :=myclick(a,i); mb[i].Tag :=i;
 mb[i].Show; end;
end;
procedure TForm1.MyClick (Sender:tobject;index:integer);
begin
 showmessage(inttostr(index));
end;
end.

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure MyClick(Sender:TObject;index:integer);//声明出错
    //改为:procedure MyClick(Sender:TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
     var MB:array [0..5] of TEdit;
          i:integer;
          a:Tobject;
    begin
     for i:=0 to 5 do
     begin
     mb[i]:=Tedit.Create (Self);
     mb[i].parent:=form1;
     mb[i].top:=100;
     mb[i].left:=100+i*150;
     //mb[i].OnClick :=myclick(a,i);
    //改为:mb[i].Onclick:=myclick(self);
        mb[i].tag :=i; mb[i].Tag :=i;
     mb[i].Show; end;
    end;
    procedure TForm1.MyClick (Sender:tobject;);
    begin
     showmessage(inttostr(TEdit(Sender).tag));//这里也要改
    end;
    end.