为什么动态生成的QRDBText在预览时看不见?(50分)

  • 主题发起人 主题发起人 deardragon
  • 开始时间 开始时间
D

deardragon

Unregistered / Unconfirmed
GUEST, unregistred user!
qrtext := TQRDBText.Create(QRBand2);
qrtext.Parent := QRBand2;
qrtext.Left := qrtext.Left + index * 80;
qrtext.Top := qrlbl.Top + 20;
qrtext.DataSet := Table1;
qrtext.DataField := Table1.Fields.Fields.AsString ;
qrtext.Visible := true;
这段程序是没有问题的,在quickrep上可以看见Table1.Fields.Fields.AsString中
的内容,而且是正确的,但预览时QuickRep1.Preview就看不见了。为什么呢?
另外,静态地设置 TQRDBText的DataSet和DataField属性,则可以将TABLE中的所以记录
内容都显示出来,但利用上面的动态创建,就不行了。试了好多次了,还是没能搞定,
请高手们帮帮忙。在大富翁上也没找到。
 
你的代碼是寫在哪兒的?
 
在主程序上,通过Button1Click来调用另一个FROM(该FROM上放置了QUICKREP和QRBAND),
有很大关系吗?
 
QrBand2的BandType属性设置的是什么?是不是preview的时候,QrBand2上的所有东西
都看不到?
 
能不能那段程序贴出来,看看。
 
qrtext.DataField := Table1.Fields.Fields.AsString ;//HERE



 
Fields[1].FieldName
 
QRBand的BandType 为rbDetail,我的代码里同时有在QRBAND上动态创建QRLABEL和QRDBTEXT,
在quickrep上可以看见第一条记录的结果(正确的),但其他记录就看不见。在预览时
可以看到QRLabel1.Caption的内容和qrlbl的内容。就是qrtext的看不见。
把qrtext.DataField := Table1.Fields.Fields.AsString ;
改为qrtext.DataField := Table1.Fields[1].FieldName;也不行,结果是一样的。
procedure TfrmSalary.Button1Click(Sender: TObject);//frmSalary是主FROM名
Var
i,index : integer;
qrlbl : TQRLabel;
qrtext: TQRDBText;
begin
with frmAllSDetail do
begin
QRLabel1.Caption := TreeView1.Items[0].Text + '工资条';
index := 1 ;
with Table1 do
begin
TableName := 'TempTable.db';
if Active then close;
open;
first;
for i := 1 to Table1.FieldDefs.Count -1 do
begin
qrlbl := TQRLabel.Create(QRBand2);
qrlbl.Parent := QRBand2;
qrlbl.Left := qrlbl.Left + index * 80;
qrlbl.Caption := FieldDefs.Items.DisplayName ;
qrlbl.Visible := true;

qrtext := TQRDBText.Create(QRBand2);
qrtext.Parent := QRBand2;
qrtext.Left := qrtext.Left + index * 80;
qrtext.Top := qrlbl.Top + 20;
qrtext.DataSet := Table1;
//qrtext.DataField := Table1.Fields.FieldName ;这句和下面那句的结果是一样的
qrtext.DataField := Table1.Fields.Fields.AsString ;
qrtext.Visible := true;
index := index + 1;
end;
close;
QRBand2.Height := Table1.FieldCount * 40;
end;
end;
frmAllSDetail.ShowModal ;
frmAllSDetail.QuickRep1.Preview ;
end;

 
有 没有 搞错

while not eof do
begin

close;//////////////??????????????????

frmAllSDetail.QuickRep1.Preview

//你 以前 用过 qr 吗????????????????????
 
我已经改好了,你再看看。没有while not eof do一样不行,而CLOSE不是这个循环里的。
而是对应 with Table1 do 的OPEN 的。至于frmAllSDetail.QuickRep1.Preview我就不懂了,
什么问题?QR以前没用过。
再加 50 分,顺便帮我把遗留的问题解决:
1.我想显示所以记录,怎么样才能显示TEMPTABLE里的所以记录。
2.报表是横向显示的,怎么样根据列数来调整宽度?现在是不够宽。
 
问题多多
1。倒数第7句,table close了怎么会有数据?
2。直接preview就可以了,不要再showmodal了。
3。为什么column title要为每条记录生成一次?多混乱!用一个Band:rbColumnHeader。
把qrlbl放在里面。
4。qrtext.DataField := Table1.Fields.FieldName

再试试:
procedure TfrmSalary.Button1Click(Sender: TObject);//frmSalary是主FROM名
Var
i,index : integer;
qrlbl : TQRLabel;
qrtext: TQRDBText;
begin
with frmAllSDetail do
begin
QRLabel1.Caption := TreeView1.Items[0].Text + '工资条';
index := 1 ;
with Table1 do
begin
TableName := 'TempTable.db';
if Active then close;
open;
for i := 1 to Table1.FieldDefs.Count -1 do
begin
qrlbl := TQRLabel.Create(QRBand2);
qrlbl.Parent := QRBand2;
qrlbl.Left := qrlbl.Left + index * 80;
qrlbl.Caption := FieldDefs.Items.DisplayName ;
qrlbl.Visible := true;

qrtext := TQRDBText.Create(QRBand2);
qrtext.Parent := QRBand2;
qrtext.Left := qrtext.Left + index * 80;
qrtext.Top := qrlbl.Top + 20;
qrtext.DataSet := Table1;
qrtext.DataField := Table1.Fields.FieldName;
qrtext.Visible := true;
index := index + 1;
end;
end;
end;
frmAllSDetail.QuickRep1.Preview ;
end;


1。应该可以显示所以记录了
2。把纸横过来打:qReport的page.Orientation设为poLandscape

别忘了你的加分啊! :-)


 
还是只有一条记录。(第一条)
 
你确定和上面的代码相同?
我刚试过的,没问题的!
 
还没搞定???
原样copy,试好后对照着改你的。
Form1放个Button。Form2放个Table,QuickRep。QuickRep上方两个QrBand。
QuickRep1.DataSet设为Table1。
第一个Band的Type为Title,第二个BandType为Detail。
别告诉我还不行!记得加分!!! :-))

procedure TForm1.Button1Click(Sender: TObject);
Var
i,index : integer;
qrlbl : TQRLabel;
qrtext: TQRDBText;
begin
with Form2 do
begin
QuickRep1.Page.Orientation := poLandscape;
index := 1 ;
with Table1 do
begin
DataBaseName := 'DBDEMOS';
TableName := 'customer.db';
if Active then close;
open;
for i := 1 to Table1.FieldDefs.Count -1 do
begin
qrlbl := TQRLabel.Create(QRBand2);
qrlbl.Parent := QRBand2;
qrlbl.Left := qrlbl.Left + index * 80;
qrlbl.Caption := FieldDefs.Items.DisplayName ;
qrlbl.Visible := true;

qrtext := TQRDBText.Create(QRBand2);
qrtext.Parent := QRBand2;
qrtext.Left := qrtext.Left + index * 80;
qrtext.Top := qrlbl.Top + 20;
qrtext.DataSet := Table1;
qrtext.DataField := Table1.Fields.FieldName;
qrtext.Visible := true;
index := index + 1;
end;
end;
end;
form2.QuickRep1.Preview ;
end;
 
to GanQuan:
在“来自:GanQuan, 时间:2002-3-8 10:01:00, ID:968934”里确实是一模一样的,但
不行,不过来自来自:“GanQuan, 时间:2002-3-9 9:32:00, ID:971462”的启示,加了
TABLE终于可以了。
但在这里我只可以给出50分,原因相信你也明白。所以我只能另外开个题,你来回答,我把
这里欠你的分数给补上来。OK?(其实也只能这样了):p
hfghfghfg的 Fields[1].FieldName是对的,
while not eof do
begin
close;//////////////??????????????????
也指出了错误,但没说明白,所以,只能。。。。。:)

 
多人接受答案了。
 
后退
顶部