delphi 中,动态生成的edit 控件问题? 20
edit控件是动态生成的,我如何给它创立一个事件例如:在程序运行时创建了5个edit控件,当我给生成的第一个edit控件输入内容后,退出时,就触发一个事件。该如保编写呢?...
edit控件是动态生成的,我如何给它创立一个事件
例如:
在程序运行时创建了5个edit控件,当我给生成的第一个edit控件输入内容后,退出时,就触发一个事件。
该如保编写呢?
急盼 展开
例如:
在程序运行时创建了5个edit控件,当我给生成的第一个edit控件输入内容后,退出时,就触发一个事件。
该如保编写呢?
急盼 展开
1个回答
展开全部
不太清楚你说什么,我的理解是:动态生成edit控件,然后,你要编辑动态生成的edit的内容,最后在退出主程序(或edit的parent)时,触发一个事件。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
myedit:Tedit;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
myedit:=Tedit.Create(application);
myedit.Parent:=self;
myedit.Top:=10;
myedit.Left:=10;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if myedit.Text<>'' then//如果myedit不为空,就响一下,并showmessage;
begin
beep;
showmessage(myedit.Text);
end;
myedit.Free;//不晓得是否有必要释放,我忘了,不过多一行也不算啥
end;
end.
另一个例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure OntbnClick(Sender: TObject);//创建一个过程,用来处理tbn被点击事件
end;
var
Form1: TForm1;
tbn:TButton;
myedit:TEdit;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
tbn:=TButton.Create(application);
with tbn do
begin
parent:=self;
caption:='确定';
left:=20;
top:=40;
end;
tbn.OnClick:=OntbnClick;//将创建的过程赋给tbn被点击事件
myedit:=TEdit.Create(application);
with myedit do
begin
parent:=self;
left:=10;
top:=10;
end;
end;
procedure TForm1.OntbnClick(Sender: TObject);
begin
if myedit.Text<>'' then//过程触发的事件
showmessage(myedit.Text);
{如果只需要判断myedit是否被编辑过,忽略为空的情况,可以改为if myedit.Modified then}
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
myedit:Tedit;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
myedit:=Tedit.Create(application);
myedit.Parent:=self;
myedit.Top:=10;
myedit.Left:=10;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if myedit.Text<>'' then//如果myedit不为空,就响一下,并showmessage;
begin
beep;
showmessage(myedit.Text);
end;
myedit.Free;//不晓得是否有必要释放,我忘了,不过多一行也不算啥
end;
end.
另一个例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure OntbnClick(Sender: TObject);//创建一个过程,用来处理tbn被点击事件
end;
var
Form1: TForm1;
tbn:TButton;
myedit:TEdit;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
tbn:=TButton.Create(application);
with tbn do
begin
parent:=self;
caption:='确定';
left:=20;
top:=40;
end;
tbn.OnClick:=OntbnClick;//将创建的过程赋给tbn被点击事件
myedit:=TEdit.Create(application);
with myedit do
begin
parent:=self;
left:=10;
top:=10;
end;
end;
procedure TForm1.OntbnClick(Sender: TObject);
begin
if myedit.Text<>'' then//过程触发的事件
showmessage(myedit.Text);
{如果只需要判断myedit是否被编辑过,忽略为空的情况,可以改为if myedit.Modified then}
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询