在Delphi里面如何把如TSpeedButton 做成数组。像VB里那样.这样他的事件写在一个里面就可以了。

解决方案 »

  1.   

    写在一个里面,你就写在一个里面也是可以的。在代码里写上TSpeedButton(x)sender。
      ……
      

  2.   

    可以啊,直接写在一个里面然后用
    (Sender as TSpeedButton).Caption := 'dfas';
      

  3.   

    a:array[0..8,0..8]of TSpeedButton
    然后用循环创建,并赋值
    a[i,j].onclick:=你自己定义的click事件
      

  4.   

    如果只是想写一个事件给多个speedbutton,
    可以用tag属性,如有四个speedButton,tag分别设置为0,1,2,3
    可以指定其click事件都是SpeedButtonGroupClick
    procedure TForm1.SpeedButtonGroupClick(Sender: TObject);
    begin
      //比较爽的写法
      listview1.viewstyle:= TViewStyle( (Sender as TSpeedButton).tag );    或
      //比较不爽的写法
       case Sender as TSpeedButton).tag of
        0: listview1.viewstyle := vsIcon;
        1: listview1.viewstyle := vsList;
            ...
      end;
    end;
      

  5.   

    gub(gub),   使用tag是正解
      

  6.   

    要和VB中一样是不可能的:) 我是从VB转过来的.
    如果你的speedbutton处理的事件代码是一样的,那就很简单,如下
    你可以这样写一个通用事件过程
    procedure SpeedButtonClick(Sender:TObject);
    begin
      if Sender is TSpeedButton then
      begin
       事件处理代码
      end
    end;
    然后把每一个子speedbutton的onclick事件指向这下通用过程如果你的speedbutton处理的事件是不一样.那就稍多一些操作
    首先你要为speedbutton们取一个有规格的名字.比如:
    spd1,spd2,spd3,spd4(四个speedbutton的name值)
    然后再写一个通用事件处理过程
    procedure SpeedButton(Sender:TObject)
    var index:Integer;
    begin
      index:=StrToInt(coyp((Sender as TSpeedButton).Name,4,1));
      case index of
      1://spd1的处理代码
      2://spd2的处理代码
      3:.......
      4:......
      end;
    end
    然后把每一个子speedbutton的onclick事件指向这下通用过程
      

  7.   

    就是通过TAG属性即可以实现。
      

  8.   

    是不是可以做一个,然后其他的都继承你的那一个Speedbutton呢?如果有新的变化,也会比较好扩展。:)