如何切换到下一个dbedit,并在最后一个dbedit上按回车时切换到下一条记录?
在一个窗体中,有几十个dbedit,我回车时就切换到下一个dbedit。并在最后一个dbedit上按回车时切换到下一条记录。
我的代码如下:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
Perform(WM_NEXTDLGCTL,0,0);
end;
end;
procedure TForm1.DBedit23KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
datamodule1.ADOQuery.Next;
if datamodule1.ADOQuery.Eof then
showmessage( '已经是最后一条记录了! ');
end;
end;
这样总是咚咚地响,怎么才能不响呀?
如果我在窗体的FormKeyPress事件中加入key:=#0; 就不响了,可是就切换不到下一条记录了。
如何既不响又能切换到下一条记录呀?
[解决办法]
把Form1的KeyPreview属性设为true
[解决办法]
为什么响我就不知道,不过觉得你的代码有点问题
{ if Key = #13 then
begin
datamodule1.ADOQuery.Next;
if datamodule1.ADOQuery.Eof then
showmessage( '已经是最后一条记录了! ');
end;}
if Key = #13 then
begin
datamodule1.ADOQuery.Post;
if datamodule1.ADOQuery.Eof then //先判断是不是最后一条记录
begin
showmessage( '已经是最后一条记录了! ');
Abort;
end;
datamodule1.ADOQuery.Next;
end;
[解决办法]
这样Form1就能响应KeyPress的消息,要不在非聚集的情况下是不会响应的。
你捕捉消息进行处理也可以
[解决办法]
楼主那样判断可以的,只不过提示会切换到最后一条记录就弹出来
if Key = #13 then
begin
with atamodule1.ADOQuery do
if Eof then
ShowMessage( '已经是最后一条记录了! ');
else
Next;
end;