控件数组的问题~! 在DELPHI中控件为动态加载的,所以不知道如何为控件数组指定处理事件,要求知道对哪个控件进行了操作~!谢谢大家~!急,在线等待~! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 procedure TForm1.FormCreate(Sender: TObject);begin MyTimer1 := TNewTimer.Create(Self); MyTimer1.OnTimer := uTimer; MyTimer1.Interval := 1000; MyTimer1.Enabled := True;end;procedure TForm1.uTimer(Sender: TObject);begin Label1.Caption := IntToStr(StrToInt(Label1.Caption) + 1);end; 你可能没看明白我的意思我问的是例如生成了五个Edit,当在其中一个keypress时,显示出他的index,也就是哪个控件进行了keypress事件~! 首先定义好各种控件的事件函数 比如动态生成一个button,定义下面的函数,procedure Buttonclick(sender:TObject);var b1:TButton;b1:=TButton.create(self);b1.parent:=self;b1.onclick:=buttonclick;要知道对那个控件进行了操作,可以用 (sender as TControl).name 就可以判定。 能不能讲详细一些,是不是窗体上没有控件,在程序的运行中在加载控件比如说,按一个按扭就加一个DBGRID到窗体上?有问题请发信息到我的E-mail:[email protected] unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DB, DBTables, DBGrids, StdCtrls, Mask;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var Memo:Tmemo;begintry memo:=Tmemo.Create(self); memo.Top:=10; memo.Left:=10; memo.Parent:=form1; memo.OnMouseUp:= mouseup; memo.Show;except memo.Free;end;end;procedure TForm1.MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin showmessage('mouse up');end;end. 上面文章版权所有: 99guo(小兵) unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, DBTables;type TForm1 = class(TForm) DataSource1: TDataSource; Table1: TTable; Button1: TButton; procedure Button1Click(Sender: TObject); procedure btnclick(sender:Tobject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementationvar btn:array [1..10] of Tbutton;{$R *.dfm}procedure Tform1.btnclick(sender:Tobject);begin showmessage('you click');end;procedure TForm1.Button1Click(Sender: TObject);begin btn[1]:=Tbutton.Create(self); btn[1].Parent:=form1; btn[1].Top:=20; btn[1].Left:=20; btn[1].OnClick:=btnclick; btn[1].Show;end;end. 上面这是个例子,你把btn[1]改为你要的第i个空件btn[i]就行了 ComponentCount代表窗体上的控件数;Components[ComponentCount]代表的是什么控件;比如Components[1]是第一个控件是什么?知道这些应该可以解决你的问题!有问题请发信息到我的E-mail:[email protected] 对,按 99guo(小兵) 说的做应该可以,加一些判断语句就可以了吧!!!有问题请发信息到我的E-mail:[email protected] webbrowser1 如何获取当前网页的句柄 两个exe使用一个文件,怎么防止同时读写? 我加载静态动态链接库为何不成功呢.狂晕... 正则表达式 DLL的问题,急!!!!!!! 超级捡分的问题!! 两个listbox! StringGrid 求Rose,或playcase工具 Delphi的克星怎样解决? 用ADO连SQLSERVER2000的Data Source设置问题 求FastReport4.6.8中文教程?
begin
MyTimer1 := TNewTimer.Create(Self);
MyTimer1.OnTimer := uTimer;
MyTimer1.Interval := 1000;
MyTimer1.Enabled := True;
end;procedure TForm1.uTimer(Sender: TObject);
begin
Label1.Caption := IntToStr(StrToInt(Label1.Caption) + 1);
end;
我问的是例如生成了五个Edit,当在其中一个keypress时,显示出他的index,也就是哪个控件进行了keypress事件~!
procedure Buttonclick(sender:TObject);var b1:TButton;b1:=TButton.create(self);
b1.parent:=self;
b1.onclick:=buttonclick;要知道对那个控件进行了操作,可以用 (sender as TControl).name 就可以判定。
比如说,按一个按扭就加一个DBGRID到窗体上?
有问题请发信息到我的E-mail:[email protected]
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DB, DBTables, DBGrids, StdCtrls, Mask;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject); procedure MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
Memo:Tmemo;
begin
try
memo:=Tmemo.Create(self);
memo.Top:=10;
memo.Left:=10;
memo.Parent:=form1;
memo.OnMouseUp:= mouseup;
memo.Show;
except
memo.Free;
end;
end;procedure TForm1.MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
showmessage('mouse up');
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables;type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure btnclick(sender:Tobject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
var
btn:array [1..10] of Tbutton;{$R *.dfm}
procedure Tform1.btnclick(sender:Tobject);
begin
showmessage('you click');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
btn[1]:=Tbutton.Create(self);
btn[1].Parent:=form1;
btn[1].Top:=20;
btn[1].Left:=20;
btn[1].OnClick:=btnclick;
btn[1].Show;
end;end.
Components[ComponentCount]代表的是什么控件;
比如Components[1]是第一个控件是什么?
知道这些应该可以解决你的问题!
有问题请发信息到我的E-mail:[email protected]
有问题请发信息到我的E-mail:[email protected]