我用QR做了一个报表,现在在打印的时候只能看到第一页,其他的数据全问溢出了,页面不能自动换页,属性我都设过了,还是不行,大家帮我看一下。
procedure Tqrpt_ysmx.beforepreview;
var
  i:integer;
  atop:integer;
  aLabel:TQRLabel;
  aLine:TQRShape;
  d1,d2,d3:Tdate;
  kh1:string;
begin
     atop:=68;
     d1:=ysquanbucx.date1;
     d2:=ysquanbucx.date2;
     kh1:=ysquanbucx.kh;     qdate.Active:=false;
     qdate.SQL.Clear;
     qdate.SQL.Add('select 日期 from 应收明细');
     qdate.SQL.Add('where 客户='''+kh1+''' and 日期>=#'+datetostr(d1) +'# and 日期<=#'+datetostr(d2) +'# group by 日期');
     qdate.Prepared;
     qdate.open;     while not qdate.Eof do
      begin
       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=0;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=16;
        aLine.Frame.Color:=clBlack;
       end;        aLabel:= TQRLabel.Create(qrpt_ysmx);
        aLabel.Parent := TitleBand1;
        with aLabel do
        begin
        AutoSize:=true;
        AutoStretch:=True;
        Font.Size:=8;
        Left :=8;
        Top := atop+2;
        Alignment:=taLeftJustify;
        d3:=qdate.Fields[0].Value;
        Caption :=datetostr(d3);
        end;       qmingxi.Active:=false;
       qmingxi.SQL.Clear;
       qmingxi.SQL.Add('select 部门,摘要,增加费,减少费 from 应收明细');
       qmingxi.SQL.Add('where 客户='''+kh1+''' and 日期=#'+datetostr(d3)+'# order by 部门');
       qmingxi.Prepared;
       qmingxi.open;        while not qmingxi.Eof do
        begin       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=66;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=16;
        aLine.Frame.Color:=clBlack;
       end;
       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=0;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=16;
        aLine.Frame.Color:=clBlack;
       end;
       
       aLabel:= TQRLabel.Create(qrpt_ysmx);
       aLabel.Parent := TitleBand1;
       with aLabel do
       begin
        AutoSize:=true;
        AutoStretch:=True;                          
        Font.Size:=8;
        Left :=75;
        Top := atop+2;
        Alignment:=taLeftJustify;
        Caption:=qmingxi.Fields[0].Value;
       end;       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=125;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=16;
        aLine.Frame.Color:=clBlack;
       end;       aLabel:= TQRLabel.Create(qrpt_ysmx);
       aLabel.Parent := TitleBand1;
       with aLabel do
       begin
        //AutoSize:=;
        AutoStretch:=True;
        Font.Size:=8;
        Left :=130;
        Top := atop+2;
        Alignment:=taLeftJustify;
        Caption :=qmingxi.Fields[1].Value;
       end;       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=433;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=16;
        aLine.Frame.Color:=clBlack;
       end;       aLabel:= TQRLabel.Create(qrpt_ysmx);
       aLabel.Parent := TitleBand1;                            
       with aLabel do
       begin
        AutoSize:=true;
        AutoStretch:=True;
        Font.Size:=8;
        Left :=437;
        Top := atop+2;
        Alignment:=taLeftJustify;
        Caption :=qmingxi.Fields[2].asstring;
       end;       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=527;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=16;
        aLine.Frame.Color:=clBlack;
       end;       aLabel:= TQRLabel.Create(qrpt_ysmx);
       aLabel.Parent := TitleBand1;
       with aLabel do
       begin
        AutoSize:=true;
        AutoStretch:=True;
        Font.Size:=8;
        Left :=531;
        Top := atop+2;
        Alignment:=taLeftJustify;
        Caption :=qmingxi.Fields[3].AsString;
       end;       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=619;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=16;
        aLine.Frame.Color:=clBlack;
       end;       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=717;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=16;
        aLine.Frame.Color:=clBlack;
       end;       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=0;
        aLine.Top:=atop+16;
        aLine.Width:=718;
        aLine.Height:=1;
        aLine.Frame.Color:=clBlack;
       end;      atop:=atop+16;
      qmingxi.Next;
      end;
      qyue.Active:=false;
      qyue.SQL.Clear;
      qyue.SQL.Add('select sum(结存)as b1 from 应收结存');
      qyue.SQL.Add('where (日期=#'+datetostr(d3) +'#) and (客户='''+kh1+''') and (结存<>0)');
      qyue.Prepared;
      qyue.Open;
     // showmessage(datetostr(d3));
     // showmessage(qyue.Fields[0].AsString);       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=0;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=17;
        aLine.Frame.Color:=clBlack;
       end;       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=619;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=17;
        aLine.Frame.Color:=clBlack;
       end;       aLabel:= TQRLabel.Create(qrpt_ysmx);
       aLabel.Parent := TitleBand1;
       with aLabel do
       begin
        AutoSize:=true;
        AutoStretch:=True;
        Font.Size:=8;
        Left :=628;
        Top := atop+2;
        Font.Style:=[fsBold];
        Alignment:=taLeftJustify;
        Caption:=qyue.Fields[0].AsString;
       end;       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=0;
        aLine.Top:=atop+16;
        aLine.Width:=718;
        aLine.Height:=1;
        aLine.Frame.Color:=clBlack;
       end;       aLine:= TQRShape.Create(qrpt_ysmx);
       aLine.Parent := TitleBand1;
       with aLine do
       begin
        aLine.Left:=717;
        aLine.Top:=atop;
        aLine.Width:=1;
        aLine.Height:=17;
        aLine.Frame.Color:=clBlack;
       end;       atop:=atop+16;
       qdate.Next;       end;
     end;
end.

解决方案 »

  1.   

    太长了,没认真看,不过怎么你只用TitleBand,而没有DetailBand,难道你的数据都是用label显示吗,是不是太辛苦了;
    还有为什么写在这里.beforepreview;为什么不先都设置好直接调用呢?
    我觉得qr一般不许要在preview和print的相关事件中加代码(特殊情况除外);
      

  2.   

    我的数据都是用label显示的。可能就是这个while do 语句里的毛病吧.再搞不定我真的挂了
      

  3.   

    我的QQ是20315567,想和各位交一个朋友,一起研究delphi,愿意的加我吧
      

  4.   

    晕倒啊,不要用那么多的label ,那会内存不够的。
      

  5.   

    不会吧,为什么只用TitleBand,而不用其他Band呢?你可以将结果集整理一下,然后使用DetialBand,如果不够用可以使用GroupBand、SubBand等。当然如果你的报表不是那种连续报表,而是固定报表,内容不多的话还可以使用QReport。否则就用其他的方法吧,比如先将数填到提供打印的Grid中,然后使用Grid的打印功能。