以下代码错在哪里??预览时怎么没有啊??
procedure TForm1.QuickRepNeedData(Sender: TObject; var MoreData: Boolean);
var MyConst:Integer;
begin
    //inc(fnum);
    MoreData:=true;
    for MyConst:=0 to list.Count-1 do
    begin
       While not QueryPrintVoucher.Eof do
       begin
          if QueryPrintVoucher.FieldByName('凭证号').AsInteger=strtoint(list.Strings[MyConst]) then
             QRLabel4.Caption:= QueryPrintVoucher.FieldByName('科目名').AsString
          else QRLabel4.Caption:= '000';
          QueryPrintVoucher.Next;
       end;
    end;
    MoreData:=false;
end;

解决方案 »

  1.   

    procedure TForm1.QuickRepNeedData(Sender: TObject; var MoreData: Boolean);
    var MyConst:Integer;
    begin
        //inc(fnum);
        MoreData:=true;
        for MyConst:=0 to list.Count-1 do
        begin
           if QueryPrintVoucher.Eof then
             QueryPrintVoucher.First;//加上这句看看
           While not QueryPrintVoucher.Eof do
           begin
              if QueryPrintVoucher.FieldByName('凭证号').AsInteger=strtoint(list.Strings[MyConst]) then
                 QRLabel4.Caption:= QueryPrintVoucher.FieldByName('科目名').AsString
              else QRLabel4.Caption:= '000';
              QueryPrintVoucher.Next;
           end;
        end;
        MoreData:=false;
    end;
      

  2.   

    测试了一下,这样可以:
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, QuickRpt, QRCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        QuickRep1: TQuickRep;
        DetailBand1: TQRBand;
        QRLabel1: TQRLabel;
        procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
        procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
          var PrintReport: Boolean);
      private
        { Private declarations }
        MyConst:integer;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses mainwin;{$R *.dfm}procedure TForm1.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
    begin
      if  MyConst<F_main.memo1.lines.count-1 then
        if F_main.ADOQuery4.Eof then
        begin
          inc(MyConst);
          F_main.ADOQuery4.First;
        end;
      if not  F_main.ADOQuery4.Eof then
        MoreData:=true
      else MoreData:=False;
      if moredata then
      begin
        if MyConst<=F_main.memo1.lines.count-1 then
        begin
          if copy(F_main.ADOQuery4.FieldByName('id').Asstring,1,4)=F_main.memo1.lines[MyConst] then
            QRLabel1.Caption:= F_main.ADOQuery4.FieldByName('name').AsString
          else QRLabel1.Caption:= '000';
          F_main.ADOQuery4.Next;
        end;
      end;
    end;procedure TForm1.QuickRep1BeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
    begin
      MyConst:=0;
    end;end.
      

  3.   

    注意此时QRLabel1要放在detail band上,并且QuickRep1不设置DataSet值。
      

  4.   

    if copy(F_main.ADOQuery4.FieldByName('id').Asstring,1,4)=F_main.memo1.lines[MyConst] then
    是什么意思??
      

  5.   

    这是我的调试环境,可以改成你的形式:          if QueryPrintVoucher.FieldByName('凭证号').AsInteger=strtoint(list.Strings[MyConst]) then
      

  6.   

    为什么都打‘000’呢?????????????
        if moredata then
        begin
           if MyConst<=list.count-1 then
           begin
              if QueryPrintVoucher.FieldByName('凭证号').AsInteger=strtoint(list.Strings[MyConst]) then
              begin
                 QRLabel4.Caption:= QueryPrintVoucher.FieldByName('科目名').AsString;
                 t:=t+1;
              end;
              while t mod 6 <> 0 do
              begin
                 QRLabel4.Caption:='000';
                 t:=t+1;
              end;
              t:=0;
              QueryPrintVoucher.Next;
           end;
        end;
      

  7.   

    为何不能自加呢???begin
        //t:=0;
        if MyConst<list.count-1 then
        begin
           if QueryPrintVoucher.Eof then
           begin
              inc(MyConst);
              QueryPrintVoucher.First;
           end;
        end;    if not QueryPrintVoucher.Eof then
           MoreData:=true
        else MoreData:=False;    if moredata then
        begin
           if MyConst<=list.count-1 then
           begin
              if QueryPrintVoucher.FieldByName('凭证号').AsInteger=strtoint(list.Strings[MyConst]) then
              begin
                 QRLabel4.Caption:= QueryPrintVoucher.FieldByName('科目名').AsString;
                 QRLabel5.Caption:= inttostr(QueryPrintVoucher.FieldByName('凭证号').AsInteger);
                 t:=t+1;//为何不能自加呢???结果不正确阿. 怎么办??
                 QRLabel6.Caption:= '记录数['+inttostr(t)+']';
              end;          QueryPrintVoucher.Next;
           end;
        end;
      

  8.   

    //t应放在private里面unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, QuickRpt, QRCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        QuickRep1: TQuickRep;
        DetailBand1: TQRBand;
        QRLabel1: TQRLabel;
        QRLabel2: TQRLabel;
        procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
        procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
          var PrintReport: Boolean);
        procedure DetailBand1AfterPrint(Sender: TQRCustomBand;
          BandPrinted: Boolean);
      private
        { Private declarations }
        MyConst,t:integer;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses mainwin;{$R *.dfm}procedure TForm1.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
    begin
      if  MyConst<F_main.memo1.lines.count-1 then
        if F_main.ADOQuery4.Eof then
        begin
          inc(MyConst);
          F_main.ADOQuery4.First;
        end;
      if not  F_main.ADOQuery4.Eof then
        MoreData:=true
      else MoreData:=False;
      if moredata then
      begin
        if MyConst<=F_main.memo1.lines.count-1 then
        begin
          if copy(F_main.ADOQuery4.FieldByName('id').Asstring,1,4)=F_main.memo1.lines[MyConst] then
          begin
            QRLabel1.Caption:= F_main.ADOQuery4.FieldByName('name').AsString;      end
          else QRLabel1.Caption:= '000';
          t:=t+1;
          QRLabel2.Caption:= '记录数['+inttostr(t)+']';
          F_main.ADOQuery4.Next;
        end;
      end;
    end;procedure TForm1.QuickRep1BeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
    begin
      MyConst:=0;
      t:=0;
    end;//控制分页
    procedure TForm1.DetailBand1AfterPrint(Sender: TQRCustomBand;
      BandPrinted: Boolean);
    begin
      if t mod 6=0 then
        QuickRep1.NewPage;
    end;end.
      

  9.   

    受益匪浅啊!!可我的意思是:每页先输出有记录的,再补足空行。 再打印下一号,如何实现ne??3Q!!!!!!!!!!!如:2号 有21条记录,则再补足3行空记录。 再打印3号.... 以此类推
      

  10.   

    自己认为:
    在MOREDATA:=TRUE;后加
    if QueryPrintVoucher.Eof then break;
    把最后的MOREDATA:=FALSE该为:
    if QueryPrintVoucher.Eof then  MOREDATA:=TRUE;有用就给分。
      

  11.   

    无须加入List判断,只要SQL.Text='select * from table order by 凭证号',就可以按凭证号分组,不足的以空行补满
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, QuickRpt, QRCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        QuickRep1: TQuickRep;
        DetailBand1: TQRBand;
        QRLabel1: TQRLabel;
        QRLabel2: TQRLabel;
        procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
        procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
          var PrintReport: Boolean);
        procedure DetailBand1AfterPrint(Sender: TQRCustomBand;
          BandPrinted: Boolean);
      private
        { Private declarations }
        a,b:string;
        t:integer;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses mainwin;{$R *.dfm}procedure TForm1.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
    begin
      if not  F_main.ADOQuery4.Eof then
        MoreData:=true
      else MoreData:=False;
      b:=F_main.ADOQuery4.FieldByName('id').Asstring;
      if moredata then
      begin
           if b=a then
           begin
             QRLabel1.Caption:= F_main.ADOQuery4.FieldByName('name').AsString;
             t:=t+1;
             QRLabel2.Caption:= '记录数['+inttostr(t)+']';
             F_main.ADOQuery4.Next;
           end else
           begin
             QRLabel1.Caption:='';
             QRLabel2.Caption:='';
             t:=t+1;
             if t mod 6=0 then
               a:=b;
           end;
      end;
    end;procedure TForm1.QuickRep1BeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
    begin
      a:= F_main.ADOQuery4.FieldByName('id').Asstring;
      t:=0;
    end;procedure TForm1.DetailBand1AfterPrint(Sender: TQRCustomBand;
      BandPrinted: Boolean);
    begin
      if t mod 6=0 then
        QuickRep1.NewPage;
    end;end.
      

  12.   

    一个帖子问了n个问题,SQL.Text:='Exec proc_name 参数列表'; Open;这样即可
      

  13.   

    不行啊!这样大的空行太多了。 我想每页先打有数据的,再在每一页补足空行。怎么处理??这样空行太多了
      if copy(F_main.ADOQuery4.FieldByName('id').Asstring,1,4)=F_main.memo1.lines[MyConst] then
          begin
            QRLabel1.Caption:= F_main.ADOQuery4.FieldByName('name').AsString;      end
          else QRLabel1.Caption:= '000';
      

  14.   

    晕,你说的不是这个意思吗,>>>>每页先输出有记录的,再补足空行。 再打印下一号,如何实现ne??3Q!!!!!!!!!!!如:2号 有21条记录,则再补足3行空记录。 再打印3号.... 以此类推打印机怎么可能先打完每页有记录的,又再回到前面去补空行呢
      

  15.   

    不好意思,稍加修改即可
    procedure TForm1.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
    begin
      if not  F_main.ADOQuery4.Eof then
        MoreData:=true
      else begin
        if t mod 6<>0 then
        begin
          MoreData:=true;
          t:=t+1;
        end else MoreData:=False;
        if MoreData then
        begin
          QRLabel1.Caption:='';
          QRLabel2.Caption:='';
        end;
        Exit;
      end;
      b:=F_main.ADOQuery4.FieldByName('id').Asstring;
      if moredata then
      begin
           if b=a then
           begin
             QRLabel1.Caption:= F_main.ADOQuery4.FieldByName('name').AsString;
             QRLabel3.Caption:= F_main.ADOQuery4.FieldByName('a1').AsString;
             t:=t+1;
             QRLabel2.Caption:= '记录数['+inttostr(t)+']';
             F_main.ADOQuery4.Next;
           end else
           begin  //以空行补满
             QRLabel1.Caption:='';
             QRLabel2.Caption:='';
             t:=t+1;
             if t mod 6=0 then
               a:=b;
           end;
      end;end;procedure TForm1.DetailBand1AfterPrint(Sender: TQRCustomBand;
      BandPrinted: Boolean);
    begin
      if (t mod 6=0) and (not  F_main.ADOQuery4.Eof) then
        QuickRep1.NewPage; //每页6条记录
    end;