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
在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