预览为什么没有数据?谁能回答?100分(100分)

L

lsyx

Unregistered / Unconfirmed
GUEST, unregistred user!
请看:打印部分
procedure TForm1.PrintButtonClick(Sender: TObject);
begin

if not Table1.RecordCount<1
then
begin

if not Assigned(pfmlsy) //pfmlxy 是报表窗体
then
Application.CreateForm(Tpfmlsy,pfmlsy);
pfmlsy.QuickRep1.Preview;
end
else
MessageDlg('报表无记录!',mtinformation,[mbok],0);
end;


pfmlxy 是报表窗体,是用的QuickRep控件。
QuickRep控件DataSet设置正确,是Form1.Table1

一般是好的,但有时没有数据,之后就再也没有数据了,
除非重新打开程序。为什么??
本人用的是 Delphi5+Access97.
 
估计这两句代码有问题:

if not Assigned(pfmlsy) //pfmlxy 是报表窗体
then
Application.CreateForm(Tpfmlsy,pfmlsy);
你可以把代码重新检查一下!

 
可试试将table的active属性false再true,祝你我都好运
 
把pfmlxy 报表窗体做成自创建窗体,
procedure TForm1.PrintButtonClick(Sender: TObject);
begin

if not Table1.RecordCount<1 then
begin

pfmlsy.QuickRep1.Preview
else
MessageDlg('报表无记录!',mtinformation,[mbok],0);
end;

试试,如可以则是
if not Assigned(pfmlsy) //pfmlxy 是报表窗体
then
Application.CreateForm(Tpfmlsy,pfmlsy);
这两句有问题,如不可以则是其它的地方有问题。
 
测试了你的程序,没发现任何问题...
数据打印不出来,那么能显示在DBGRID中吗?
 
TO Kent:
<h2>有时</h2>数据打印不出来,之后就再也没有数据了,
除非重新打开程序。
但是总能显示在DBGRID中
 
检查打开报表时,数据库是否在Eof。
常常有这种事。某些操作使数据库到了Eof,当你在报表中用TTable,TQuery
时,当然没有数据了。
 
你的QUICKREPORTR的dataset属性是否有设?
 

在打开窗口时(试加一行)

Table1.refresh;
 
我遇过这种问题,其实是因为第一次运行之后,由于QReport自动把其对应的 Dataset 遍历了一遍,直到 Eof,所以,下次再打开时,自然就找不到数据了,
可以在打开之前,把该 DataSet 定位一下;同时,QReport 所在的 Form 用过
以后,要 Free 掉,再次打开,就不会受以前的影响了。
 
>>
continue,please
 
procedure TForm1.PrintButtonClick(Sender: TObject);
begin

if not Table1.Active then
Table1.Open;
Table1.Filtered:=False;
Table1.CancelRange;
Table1.First;
if not Table1.RecordCount<1
then
begin

if not Assigned(pfmlsy) //pfmlxy 是报表窗体
then
Application.CreateForm(Tpfmlsy,pfmlsy);
pfmlsy.QuickRep1.Preview;
end
else
MessageDlg('报表无记录!',mtinformation,[mbok],0);
end;


另外,在pfmlsy的OnDestroy事件中加上:
pfmlsy:=nil;
//从你的程序的用法上看,这点很重要.

 
多半是pfmlsy创建了多次的缘故。
看看
1、有没有设成自动创建了?
2、用完以后
pfmlsy.Free;
pfmlsy:=Nil;
就万无一失了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
519
import
I
I
回复
0
查看
609
import
I
顶部