各位看一看我的以下程序,是有关打印预览的(90分)

  • 主题发起人 主题发起人 laoban1
  • 开始时间 开始时间
L

laoban1

Unregistered / Unconfirmed
GUEST, unregistred user!
各位看一看我的以下程序,预想是:在窗体F_dayin上,有一个组合框有四个下位选项'按单位名称查询''按单位编号查询 '按工资年份查询' '按工资月份查询',还有一个文本框,可以在选择完一个选项后在文本框edit2.text中输入条件,单击打印预览则出现符合此条件的一系列记录,但是当运行程序时,单击打印预览按钮并不出现预览(实际上我输入的条件表中是有的应该出现才对,连预览窗体都不出现),而是弹出对话框“没有符合条件的记录,请重新输入条件!”,请帮忙看看下边的程序有什么问题吗?
其中窗体F_baobiao里放着QuickRep1,query1等控件。
procedure TF_dayin.SpeedButton2Click(Sender: TObject);
begin
if combobox2.text='按单位名称查询' then
with F_baobiao.Query1 do
begin
close;
sql.add('select * from GZB1');
sql.add('where 单位名称=:zhi');
parambyname('zhi').Asstring:=edit2.text;
open;
F_baobiao.Show;
F_baobiao.QuickRep1.preview;
end;

if combobox2.text='按单位编号查询' then
with F_baobiao.Query1 do
begin
close;
sql.add('select * from GZB1');
sql.add('where 单位编号=:zhi');
parambyname('zhi').asstring:=edit2.text;
open;
F_baobiao.QuickRep1.preview;
end;

if combobox2.text='按工资年份查询' then
with F_baobiao.Query1 do
begin
close;
sql.add('select * from GZB1');
sql.add('where 工资年份=:zhi1');
parambyname('zhi').Asstring:=edit2.text;
open;
F_baobiao.QuickRep1.preview;
end;

if combobox2.text='按工资月份查询' then
with F_baobiao.Query1 do
begin
close;
sql.add('select * from GZB1');
sql.add('where 工资月份=:zhi1');
parambyname('zhi').Asstring:=edit2.text;
open;
F_baobiao.QuickRep1.preview;
end
else
begin
showmessage('没有符合条件的记录,请重新输入条件!');
edit2.Text:='';
edit2.SetFocus;
end;
end;
 
邏輯錯誤:
if combobox2.text='按单位名称查询' then
... (1)
if combobox2.text='按单位编号查询' then
... (2)
if combobox2.text='按工资年份查询' then
... (3)
if combobox2.text='按工资月份查询' then
... (4)
else
... //這個else
與(4)是配對的.所以只要(4)條件不成立,就會執行else
中的語句.
應該改為
if combobox2.text='按单位名称查询' then
begin
...end
else
if combobox2.text='按单位编号查询' then
begin
...end
else
if combobox2.text='按工资年份查询' then
begin
...end
else
if combobox2.text='按工资月份查询' then
begin
...end
else
begin
showmessage('没有符合条件的记录,请重新输入条件!');
edit2.Text:='';
edit2.SetFocus;
end;
 
我已经照改了,并且每一个判断前又加了一条语句sql.clear;
如:if combobox2.text='按工资月份查询' then
with F_baobiao.Query1 do
begin
close;
sql.clear;
sql.add('select * from GZB1');
sql.add('where 工资月份=:zhi1');
parambyname('zhi').Asstring:=edit2.text;
open;
F_baobiao.QuickRep1.preview;
end
但是还是出现那个提示'没有符合条件的记录,请重新输入条件!',是不是不能跨窗体调用
F_baobiao.Query1
 
你還是設些斷點,根蹤調試吧.另外,最好別用下面的寫法.
if combobox2.text='按工资月份查询'then
...
我懷疑你的這些比較條件都不符合,沒有執行查詢和報表預覽語句.改成以下格式吧:
case ComboBox2.ItemIndex of
0: begin

end;
1: begin
end;
2: begin
end;
3: begin
end;
else
begin
showmessage('没有符合条件的记录,请重新输入条件!');
edit2.Text:='';
edit2.SetFocus;
end;
 
whti querydo

begin
sql.clear;
sql.add('select * from GZB1');
case ComboBox2.ItemIndex of
0: sql.add('where 单位名称=:zhi');
1: sql.add('where 单位编号=:zhi');
2: sql.add('where 工资年份=:zhi1');

3: sql.add('where 工资月份=:zhi1');

parambyname('zhi').Asstring:=edit2.text;
close;
open;
if recordcount > 0 then

F_baobiao.QuickRep1.preview
else
showmessage('没有符合条件的记录,请重新输入条件!');
end
如何?
 
报表倒是显示了,但是每次显示的符合条件的记录只有一条,实际上有许多符合条件的记录
这是怎么回事?
 
以下是那个打印预览程序的改写,基本上没有什么问题,就是有一条语句出现提示
parambyname('zhi').Asstring:=edit2.text;这段出现的提示常量表达式溢出,是怎么回事
procedure TF_dayin.SpeedButton2Click(Sender: TObject);
begin
with F_baobiao.Query1do
begin
close;
sql.clear;
sql.add('select * from GZB1');
case ComboBox2.ItemIndex of
0: sql.add('where 单位名称=:zhi');
1: sql.add('where 单位编号=:zhi');
2: sql.add('where 工资月份=:zhi');
3: sql.add('where 工资年份=:zhi');
parambyname('zhi').Asstring:=edit2.text;//这段出现的提示就是常量表达式溢出
open;
if recordcount>0 then
F_baobiao.QuickRep1.preview
else
begin
showmessage('没有符合条件的记录,请重新输入条件!');
edit2.Text:='';
edit2.SetFocus;
end;
end;
end;

 
恩 不应该阿 我得很正常
 
能打印预览报表了,但是出现的问题是当输入的条件并不在数据表中时,也显示内容,是一个空的表,我的想法是当没有符合条件的记录时,给出提示就行了,没有必要打印一张空表啊?有什么办法吗?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
639
import
I
后退
顶部