我的动态生成的按钮是N个,从INI里调用字符生成(生成的caption为str1[i]数组)。每个生成的按钮点击都有自己的属性是打开不同的文件,打开文件的路径也是从INI文件里调用出来的(路径的数组为str2[i]),一个按钮对应一个路径。问题是怎么写这个触发函数,下面这个写法肯定是不行的,因为调用不了每个按钮不同的路径,请问大家应该怎么写?
var
  temp:Tbutton;
..........................(此处省略生成按钮的杂项,返回了两个数组的值)
begin
   with TButton.Create(self) do
 begin
  temp.parent:=pannel1;
  temp.Caption :=str1[1];
  temp.onclick:=myclick; 
 end;
end;procedure TForm1.myclick(Sender: TObject);
begin
  showmessage('clicked');
end;

解决方案 »

  1.   

    var
      temp:Tbutton;
    ..........................(此处省略生成按钮的杂项,返回了两个数组的值)
    begin
       with TButton.Create(self) do
     begin
      temp.parent:=pannel1;
      temp.Caption :=str1[1];
      temp.tag:='你的路径';
      temp.onclick:=myclick; 
     end;
    end;procedure TForm1.myclick(Sender: TObject);
    begin
      showmessage(TButton(sender).tag);
    end;
      

  2.   

    按你的写法是把temp.tag:='你的路径'换成  temp.tag:=str2[1];是吗?但是生成上也有问题比如这些按钮都是我点击botton1生成的,点两次就生成了2次一样的,pannel里又鑫出了同样的按钮,怎么办?
    var
      temp:Tbutton;
    ..........................(此处省略生成按钮的杂项,返回了两个数组的值)
    begin
       with TButton.Create(self) do
     begin
      temp.parent:=pannel1;
      temp.Caption :=str1[1];
      temp.tag:=str2[1];
      temp.onclick:=myclick; 
     end;
    end;procedure TForm1.myclick(Sender: TObject);
    begin
      showmessage(TButton(sender).tag);
    end;
      

  3.   

    不对啊,不行,temp.tag:=i;这样才行,不然运行错误,大家都来看看吧
      

  4.   

    请大家来看看
    我的意思是在myclick()中能解决按钮的所含的路径问题,在myclick()不可能直接引用上面那个函数的数组str2[]吧,应该怎么解决这个问题
      

  5.   

    ..........
    var
    tempI :integer;............
    tempi:=0;
    ...........var
      temp:Tbutton;
    ..........................(此处省略生成按钮的杂项,返回了两个数组的值)
    begin
       with TButton.Create(self) do
     begin
      temp.parent:=pannel1;
      temp.Caption :=str1[tempI];
      temp.tag:=str2[tempI];
      temp.onclick:=myclick; 
     end;
     inc(tempI)
    end;procedure TForm1.myclick(Sender: TObject);
    begin
      showmessage(TButton(sender).tag);
    end;