动态控件数组的事件处理程序怎么写呀,在线等,急

houyongdong 2003-10-16 02:39:22
我的程序:
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;
执行我按鼠标没有反映,但单个控件可以的。求各个大虾救救则个,我都被老板逼疯了。
...全文
35 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
vargent77 2003-10-17
  • 打赏
  • 举报
回复
同意前面几位意见,但我觉得这样整个界面遍历会好点,时间不多,留个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);
............
}
Erice 2003-10-17
  • 打赏
  • 举报
回复
joky1981() ,windyhero(西门吹雪) 的回答都不错,好拉,可以揭贴了
waysoft 2003-10-17
  • 打赏
  • 举报
回复
up
windyhero 2003-10-17
  • 打赏
  • 举报
回复
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上测试过,可以的
houyongdong 2003-10-17
  • 打赏
  • 举报
回复
各位虾哥,不好意思,我写错了,上面我忘了写一个onmouseup,而且,我在放tempstring的panel中,把panel的enabled设为了false。但是,为表我的诚意和不忘大家的辛苦,我给分情况和原因如下:
joke1981:10分;没有看清我的问题,是控件数组。
windyhero:25分;非常感谢,还提供了曾经测试过。
vargent77:5分;虽然是c++语言,但是效果一样,给5分
hiflower:虽然给出的没有找到症结所在,但给我的程序有其他的参考价值,给10分。
大家满意吗^_^
hiflower 2003-10-16
  • 打赏
  • 举报
回复
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;
joky1981 2003-10-16
  • 打赏
  • 举报
回复
看了这个例程你就知道了

unit Unit1;

interface

uses
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.
pankun 2003-10-16
  • 打赏
  • 举报
回复
for i:=0 to 10 do
begin
teamstring[i]:=tstringgrid.create(Form1);
teamstring[i]:=teamstringmouseup;
end;

没测试.你试试吧.

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧