我的程序:
public
   teamstring:array[0..20] of Tstringgrid;
procedure TeamStringMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
过程:
  for i:=0 to 10 do
  begin
     teamstring[i]:=tstringgrid.create(self);
     teamstring[i]:=teamstringmouseup;
  end;
procedure TeamStringMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
//
end;
执行我按鼠标没有反映,但单个控件可以的。求各个大虾救救则个,我都被老板逼疯了。

解决方案 »

  1.   

    for i:=0 to 10 do
      begin
         teamstring[i]:=tstringgrid.create(Form1);
         teamstring[i]:=teamstringmouseup;
      end;没测试.你试试吧.
      

  2.   

    看了这个例程你就知道了unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button: TButton;
        procedure ButtonClick(Sender: TObject);
        procedure MyMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
        procedure MyMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
        procedure MyMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
        procedure MyButtonClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      Count: Integer = 0;
      CanMove: Boolean = false;
      StartX, StartY : Integer;implementation{$R *.dfm}procedure TForm1.ButtonClick(Sender: TObject);
    var
      MyLabel: TLabel;
      MyButton: TButton;
    begin
      Inc(Count);
      MyLabel:= TLabel.Create(self);
      MyButton:= TButton.Create(self);
      MyLabel.Parent:= Form1;
      MyButton.Parent:= Form1;
      MyLabel.Left:= (Count-1)* 50;
      MyButton.Left:= (Count-1)* 80;
      MyLabel.Top:= (Count-1)* 20;
      MyButton.Top:= (Count-1)* 20;
      MyLabel.Name:= 'Label'+IntToStr(Count);
      MyButton.Name:= 'Button'+IntToStr(Count);
      MyLabel.Caption:= 'Label'+IntToStr(Count);
      MyButton.Caption:= 'Button'+IntToStr(Count);
      MyButton.OnClick:= MyButtonClick;
      MyLabel.OnMouseDown:= MyMouseDown;
      MyLabel.OnMouseMove:= MyMouseMove;
      MyLabel.OnMouseUp:= MyMouseUp;
    end;procedure TForm1.MyButtonClick(Sender: TObject);
    begin
      showmessage(TButton(Sender).Name);
    end;procedure TForm1.MyMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      CanMove:= true;
      StartX:= x;
      StartY:= y;
    end;procedure TForm1.MyMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
    //
      if CanMove then
        begin
          Tlabel(sender).Create();
          TLabel(Sender).Left:= TLabel(Sender).Left+ x-StartX;
          TLabel(Sender).Top:= TLabel(Sender).Top+ y-StartY;
        end;
    end;procedure TForm1.MyMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
    //
    CanMove:= false;
    end;end.
      

  3.   

    for i:=0 to 10 do
      begin
         teamstring[i]:=tstringgrid.create(self);
         teamstring[i]:=teamstringmouseup;
         teamstring[i].Tag:=i;
      end;
    procedure TeamStringMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      case tstringgrid(Sender).Tag of
        0:...
        1:...
        ...
      end;end;
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i : integer;
    begin
      for i:=0 to 10 do
      begin
         teamstring[i]:=tstringgrid.create(self);
         teamstring[i].Parent := Self;
         teamstring[i].Top := i*20;
         teamstring[i].Height := 20;
         teamstring[i].OnMouseUp := TeamStringMouseUp;
      end;
    end;procedure TForm1.TeamStringMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
        showmessage('ok');
    end;我在delphi7上测试过,可以的
      

  5.   

    joky1981() ,windyhero(西门吹雪) 的回答都不错,好拉,可以揭贴了
      

  6.   

    同意前面几位意见,但我觉得这样整个界面遍历会好点,时间不多,留个bcb例子
         for(int i=0;i<MainFrm->ComponentCount;++i)
            {
                 TButton* pButton=dynamic_cast<TButton*>(MainFrm->Components[i]);
                 if(pButton)//初始化窗体Button供host使用
                    {
                        Buttons[j++]=pButton;
                    }
    void __fastcall TMainFrm::Button1MouseUp
    {TButton* btn=dynamic_cast<TButton*>(Sender);
    tag=static_cast<unsigned char>(btn->Tag);
    ............
    }
      

  7.   

    各位虾哥,不好意思,我写错了,上面我忘了写一个onmouseup,而且,我在放tempstring的panel中,把panel的enabled设为了false。但是,为表我的诚意和不忘大家的辛苦,我给分情况和原因如下:
    joke1981:10分;没有看清我的问题,是控件数组。
    windyhero:25分;非常感谢,还提供了曾经测试过。
    vargent77:5分;虽然是c++语言,但是效果一样,给5分
    hiflower:虽然给出的没有找到症结所在,但给我的程序有其他的参考价值,给10分。
    大家满意吗^_^