本人在form1中动态创建了10个aled组件。代码如下:
sencond:array of Taled;
setlength(sencond,10);
for i:=0 to 10 do
begin
    sencond[i]:=Taled.Create(self);    //SHAPE组件的创建
    sencond[i].Parent :=form1 ;
    sencond[i].TrueColor:=clgray;
    sencond[i].Height :=22 ;
    sencond[i].Width :=22;
    sencond[i].Left:= round(x+radius*cos(alpha*i)-ab/2)+xshapeshift;
    sencond[i].Top :=round(y-radius*sin(alpha*i)-ab/2)+yshapeshift;
    sencond[i].Tag:=i+1;
end;
我想让tag值为1,3,5,7,9的ALED组件有onclick事件,并且点击这5个有
onclick事件组件后都弹出同一个窗体form2。在窗体form2中有一个label组件,
该label组件是用于显示aled组件的tag值的。比如点击tag值为1的aled组件
后弹出form2窗体,form2窗体的label组件就显示为1,点击tag值为3的就显示3
,请问该程序怎么编?
还有当随意点击这几个有onclick事件的组件中的一个时,系统是怎么知道我点
击是这个ALED呢?

解决方案 »

  1.   

    procedure ALEDClick(Sender : TObject);
    var
      t : ALED;
    begin
      if Sender is ALED then
      begin
        t := Sender as ALED;
        if (t.tag mod 2) = 1 then
        begin
          //form2 := TForm2.Create (self);
          form2.label1.caption := inttostr (t.tag);
          form2.Show();
        end;
      end;
    end;
      

  2.   

    TO syl79() 
       我已经试过了你的程序,可以运行,但是要弹出很多的form2窗体,如点击tag值为1的aled组件
    会弹出一个label.caption为1的form2的窗体.但点击tag值为3的aled组件时,又要弹出另一个form2窗体.原来的不会消失.是怎么回事啊?
      

  3.   

    procedure ALEDClick(Sender : TObject);
    var
      t : ALED;
    begin
      if Sender is ALED then
      begin
        t := Sender as ALED;
        if (t.tag mod 2) = 1 then
        begin
          if not Assigned(Form2) then //加入这句
            form2 := TForm2.Create (self);
          form2.label1.caption := inttostr (t.tag);
          form2.Show();
        end;
      end;
    end;
    //再在Form2的Close事件中加入
    Action := caFree;//在Form2的OnDestor事件中加入
    Form2 := nil;
    即可
      

  4.   

    to hxgaa() 
    可能是窗体没有释放的原因吧!
      

  5.   

    现在又有新的问题啦。
     就是要动态创建Taled组件和Tlabel组件。Tlabel组件的作用是用于显示对应的Taled
    组件的序号。比如创建第一个Taled后,label的caption值为1,第二个Taled组件,label的caption 值为2。
    代码如下:procedure TForm1.Button1Click(Sender: TObject);
     var    
    sencond:array of Taled;
     newbtn: array of Tlabel;
     i:integer;begin
     setlength(newbtn,10);
    setlength(sencond,10);for i:=0 to 9 do
    begin
        sencond[i]:=Taled.Create(self);    
        sencond[i].Parent :=form1 ;
        sencond[i].TrueColor:=clgray;
        sencond[i].Height :=22 ;
        sencond[i].Width :=22;
        sencond[i].Left:= 50+i*30;
        sencond[i].Top :=100;
        sencond[i].Tag:=i+1;
        sencond[i].OnClick:=click;    newbtn[i]:=Tlabel.Create(self);    
        newbtn[i].Parent :=form1 ;
        newbtn[i].Height :=22 ;
        newbtn[i].Width :=22;
        newbtn[i].Left:= 50+i*30;
        newbtn[i].Top :=120;end;
        for i:=0 to 9 do
        begin
        newbtn[i].Caption:=inttostr(i+1);
        end;
    end;
    现在我还是让tag值为1,3,5,7,9的ALED组件有onclick事件,但在点击有
    onclick事件的aled组件后,让form2中的label的caption值显示aled组件相对应的
    label组件的值。
       这又怎么做呢?我对对象还不是很了解,只有多多看看你们的拉。谢谢!