我做了两个控件组 代码如下 SetLength(Btn,100);
SetLength(mmo,100);
a:=a+1;
Btn[a]:=TButton.Create(self);
Btn[a].Parent:=Self;
Btn[a].Caption:='111';
btn[a].Top:=a*50;
btn[a].OnClick:=btnClick;
mmo[a]:=TMemo.Create(self);
mmo[a].Parent:=Self;
mmo[a].Top:=a*40;
mmo[a].Left:=100;如何让 btn[*]按下的时候 对应的mmo[*]有响应呢 。

解决方案 »

  1.   

    你可以把Botton和Memo放在同一个结构体中,这样就可以了。
    SetLength(Btnmmo,100);
    a:=a+1;
    Btnmmo[a].Button:=TButton.Create(self);
    Btnmmo[a].Button.Parent:=Self;
    Btnmmo[a].Button.Caption:='111';
    Btnmmo[a].Button.Top:=a*50;
    Btnmmo[a].Button.OnClick:=btnClick;
    Btnmmo[a].Memo:=TMemo.Create(self);
    Btnmmo[a].Memo.Parent:=Self;
    Btnmmo[a].Memo.Top:=a*40;
    Btnmmo[a].Memo.Left:=100;
      

  2.   

    tag里面写个值,然后点击的时候判断下就好....
      

  3.   

    如果Button与Memo对应,可以这样试试:
    SetLength(Btn,100);
    SetLength(mmo,100);
    a:=a+1;
    Btn[a]:=TButton.Create(self);
    Btn[a].Parent:=Self;
    Btn[a].Caption:='111';
    btn[a].Top:=a*50;
    btn[a].OnClick:=btnClick;
    btn[a].Tag:=a; //关联一下
    mmo[a]:=TMemo.Create(self);
    mmo[a].Parent:=Self;
    mmo[a].Top:=a*40;
    mmo[a].Left:=100;在BtnClick事件中写if High(mmo)<Sender.Tag then exit; //判断是否越界
    if Assigned(Mmo[Sender.Tag) then //如果存在,则
     begin
      with Mmo[Sender.Tag] do
       begin
         //进行处理
       end;
     end;
      

  4.   

    我突然想到的办法  从外界传一个参数edt1.Textt:='Bt'+edt1.Text;
    m:='Mo'+edt1.Text;
    SetLength(Btn,100);
    SetLength(mmo,100);
    a:=a+1;
    Btn[a]:=TButton.Create(self);
    Btn[a].Parent:=Self;
    Btn[a].Caption:='111';
    btn[a].Top:=a*50;
    btn[a].OnClick:=btnClick;
    Btn[a].Name:=t;
    mmo[a]:=TMemo.Create(self);
    mmo[a].Parent:=Self;
    mmo[a].Top:=a*40;
    mmo[a].Left:=100;
    mmo[a].OnClick:=mmoClick;
    mmo[a].Name:=m;
      

  5.   

    wywry 方法挺好懂 。
    Bear_hx 的没看懂了 。