向大家请教一个关于QReport的问题 (10分)

  • 主题发起人 主题发起人 TENTODBV
  • 开始时间 开始时间
T

TENTODBV

Unregistered / Unconfirmed
GUEST, unregistred user!
Form1的数据集ADOQuery1有一个字符串型字段color,里面有多条记录,但总共只有三种取值:red,green,yellow代表交通灯的三种颜色。
在Form2添加QuickRep1,添加Detailand1,在Detailand1里面放三个QRShape控件:QRShape1(对应红灯),QRShape2(对应绿灯),QRShape3(对应黄灯),并把shape属性设为圆形qrsCircle,分别代表红绿黄三色灯。
现在我想实现的功能是按ADOQuery1中每条记录的颜色值打印交通灯颜色状态记录。例如,当前颜色为红色,则把QRShape1置为红色,QRShape2和QRShape3设成白色。
我的程序代码如下:(存在的问题是:打印出来的全都是对应记录集中的最后一条记录的值)
procedure TForm1.Button1Click(Sender: TObject);
var
SL1:TStringList;
i:integer;
txtline:string;
begin
SL1:=TStringList.Create;
SL1.Add('red');
SL1.Add('gleen');
SL1.Add('yellow');
SL1.Add('yellow');
SL1.Add('red');
SL1.Add('green');
with ADOQuery1do
begin
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(Application.ExeName)+'红绿灯.mdb';
SQL.Clear;
SQL.Add('delete from data');
ExecSQL;
close;
SQL.Clear;
SQL.Add('select color from data');
open;
end;

for i:=0 to SL1.Count-1do
begin
ADOQuery1.Append;
ADOQuery1.Fields[0].Value:=SL1;
ADOQuery1.Post;
end;
RichEdit1.Text:=SL1.Text;
ADOQuery1.Recordset.MoveFirst;
with ADOQuery1.Recordsetdo
begin
while not Eofdo
begin
txtline:=Fields['color'].Value;
if txtline='red' then
begin
Form2.QRShape1.Brush.Color:=clRed;
Form2.QRShape2.Brush.Color:=clWhite;
Form2.QRShape3.Brush.Color:=clWhite;
end
else
if txtline='green' then
begin
Form2.QRShape1.Brush.Color:=clWhite;
Form2.QRShape2.Brush.Color:=clgreen;
Form2.QRShape3.Brush.Color:=clWhite;
end
else
if txtline='yellow' then
begin
Form2.QRShape1.Brush.Color:=clWhite;
Form2.QRShape2.Brush.Color:=clWhite;
Form2.QRShape3.Brush.Color:=clyellow;
end;
MoveNext;
end;
end;
Form2.QuickRep1.Preview;
with ADOQuery1do
begin
SQL.Clear;
SQL.Add('delete from data');
ExecSQL;
end;
end;

这个问题是由这个问题简化而来,大家可以去看看,在那里回答也行。
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2007621
 
procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
begin
if bPrint then
//最好设置一个开关,因为只要一移动记录就会触发此事件。
防止干扰其他过程。
begin
Shape1.Brush.Color := StringToColor(DataSet.Fields[0].AsString);
end;
end;
 
打印出来的全都是对应记录集中的最后一条记录的值——这是自然的,因为在preview之前你赋的Color值是qry里最后一条记录的。
 
在报表中放三个不同颜色的Shape在同一个位置
使用打印条件决定打哪个
 
问题已经解决,主要是参照realLearning的建议
 
to realLearning:
真抱歉,我本想把8分给你的,结果眼花了。这样吧,我在足彩投注单打印的那个帖子里多给你分吧。
 
to TENTODBV:
没能帮上忙很抱歉,要不,我开个帖子把8分还给你吧^_^
 
分就不用还了。感谢你的回帖。
 

Similar threads

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