我的一个combobox要完成的功能是:第一次回车进行与数据连接查到相关数据在其下拉中显示出来.选中相关数据后再回车,光标定位到下一个控件.我的程序如下:不过问题是这段程序不是很顺利,有时要回车两次数据才显示出来,
procedure TForm2.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then
if tag=0 then begin
begin
with datamodule1.adoqueryjbqk do
begin
close;
Sql.Clear;
Sql.Add('select sxmc from mingxi where sxlbid=010 and sxpy like '''+combobox1.text+'%''' );
Open;
combobox1.items.clear;
First;
while not eof do
begin
combobox1.items.add(fieldbyname('sxmc').asstring);
Next;
end;
end;
end;
if datamodule1.adoqueryjbqk.RecordCount > 0 then begin
tag := 1;
end
else
begin
tag := 0;
end;
end
else begin
tag := 0;
edit10.SetFocus;
end;
end;
procedure TForm2.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then
if tag=0 then begin
begin
with datamodule1.adoqueryjbqk do
begin
close;
Sql.Clear;
Sql.Add('select sxmc from mingxi where sxlbid=010 and sxpy like '''+combobox1.text+'%''' );
Open;
combobox1.items.clear;
First;
while not eof do
begin
combobox1.items.add(fieldbyname('sxmc').asstring);
Next;
end;
end;
end;
if datamodule1.adoqueryjbqk.RecordCount > 0 then begin
tag := 1;
end
else
begin
tag := 0;
end;
end
else begin
tag := 0;
edit10.SetFocus;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货