Form1上放有10个TDbedit(DBEdit1,DBEdit2,....DBEdit10):
如何实现以下功能:
procedure TForm1.DBEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then DBEdit2.SetFocus;
end;procedure TForm1.DBEdit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then DBEdit3.SetFocus;
end;procedure TForm1.DBEdit3KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then DBEdit4.SetFocus;
end;........如何把它们统一起来,写成一个统一的过程或函数,上面的方法太笨了,
假如有30个TDBedit的话,那令人太难受了,
如何进行简化,如何把它们统一起来?
如何实现以下功能:
procedure TForm1.DBEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then DBEdit2.SetFocus;
end;procedure TForm1.DBEdit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then DBEdit3.SetFocus;
end;procedure TForm1.DBEdit3KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then DBEdit4.SetFocus;
end;........如何把它们统一起来,写成一个统一的过程或函数,上面的方法太笨了,
假如有30个TDBedit的话,那令人太难受了,
如何进行简化,如何把它们统一起来?
解决方案 »
- 在线求教:如何将DELPHI关键字定义为类属性?
- 我用Reportmachine 3.0遇到大难题啊,帮帮忙
- 如何中止一个存储过程(TADOQuery)的执行
- idhttp与www.google.com的奇怪问题
- 关于ListView中控制某列的宽度固定为零(即,相当于隐藏该列!)
- 三维数组可以定义多大
- delphi7企业rip版正在下载,有人要吗?
- 100分请高手帮忙解决如何修改窗体调用的文字!详情请进!!
- 请问在程序链接数据库中,怎样可以在变为可执行文件后,数据库文件的路径可以随便放?
- 超级菜鸟问题,关于 TUpdateSql 控件
- 定制软件,有谁会做请联系
- 请问那里有将c/c++代码转换成delphi代码的程序
var
IntLoop,IntFocus:Integer;
begin
if Key=#13 then
begin
IntFocus:=1;
for IntLoop:= 0 to ComponentCount-1 do
begin
if (Components[IntLoop] is TEdit) then
begin
if TEdit(Components[IntLoop]).Focused then
IntFocus:=IntLoop+1;
end
end;
if IntFocus=ComponentCount then
IntFocus:=IntFocus-1;
try
TEdit(Components[IntFocus]).SetFocus;
except
Exit;
end;
end;
end;
这程序有点Bug,那就是创建组件时要按顺序来,否则还是不能达到像“管家婆“那样的轻松。
begin
if Key = #13 then
PostMessage((Sender as TDBEdit).Handle,WM_KEYDOWN,VK_TAB,0);
end;—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
begin
if Sender = (DBEdit1 as TObject) then
...
else if Sender = (DBEdit2 as TObject) then
...
else if Sender = (DBEdit3 as TObject) then
...
else if Sender = (DBEdit4 as TObject) then
...
else if Sender = (DBEdit5 as TObject) then
...
end;
当然,还有更简化的办法,嘿嘿……================================================================
人生最大的幸福莫过于顿顿有玉米吃
(CSDN 论坛助手,挺好使!俺们拨号上网的有福了)
begin
if Key = #13 then
PostMessage((Sender as TDBEdit).Handle,WM_KEYDOWN,VK_TAB,0);
end;然后将每个DBEdit的KeyPress事件都选择为DBEdit1KeyPress,按顺序排列每个DBEdit的TabOrder。—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
人生最大的幸福莫过于顿顿有玉米吃
(CSDN 论坛助手,挺好使!俺们拨号上网的有福了)
procedure TForm1.DBEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
(Sender as TDBEdit).SETFOCUS;
end;
然后,在DBEDIT2..DBEDIT10中的EVENTS中的ONKEYPRESS选中DBEDIT1的ONKEYPRESS
OK!
知音!知音!知音!知音!知音!知音!知音!知音!
宠辱不惊,看庭前花开花落,去留无意,望天上云卷云舒。
procedure TForm1.DBEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
(Sender as TDBEdit).SETFOCUS;
end;
然后在FormCreate之类的事件中指定:
procedure TForm1.FormCreate(Sender: TObject);
var
iCount : Integer;
begin
for iCount := 0 to ComponentCount - 1 do
begin
if (Components[iCount] is TDBEdit) and (Components[iCount].Tag = 1) then
begin
TDBEdit(Components[iCount]).OnKeyPress := DBEdit1KeyPress;
end;
end;
end;