想实现quickreport报表内容在超过一页时缩小detailband1字体然后重新预览最终报表内容只打印一页出来
procedure TPrintReport.previewBtnClick(Sender: TObject);
var
  i:integer;
begin
  QuickRep1.Prepare;
  if QuickRep1.QRPrinter.PageCount>1 then
    begin
      for i:=0 to detailband1.ControlCount-1 do
      begin
        if detailband1.Controls[i] is tqrrichtext then
        begin
          tqrrichtext(detailband1.Controls[i]).Font.Size:=tqrrichtext(detailband1.Controls[i]).Font.Size-1;
        end;
      end;
      PrintReport.previewBtnClick(Sender);
    end;
  QuickRep1.Preview;
end;第二次执行到QuickRep1.Prepare时就报内存错误了,求大家指教

解决方案 »

  1.   

    改变字体大小还不行的,还要改变band的高度;还有再次执行previewBtnClick时,进入了递归,
    QuickRep1.Preview;会创建多次,所以要在previewBtnClick后面加上Exit;下面写了一个测试的,band高度和Font.Size大小自己控制吧,用的是TQRDBText
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
      QuickRep1.Prepare;
      if QuickRep1.QRPrinter.PageCount>1 then
      begin
        for i:=0 to QRBand1.ControlCount-1 do
        begin
          if QRBand1.Controls[i] is TQRDBText then
             TQRDBText(QRBand1.Controls[i]).Font.Size:=TQRDBText(QRBand1.Controls[i]).Font.Size-1;
          QRBand1.Height:=QRBand1.Height-2;
        end;
        Button1Click(Sender);
        Exit;
      end;
      QuickRep1.Preview;
    end;
      

  2.   

    to kaikai_kk
    我这样实现了,procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
      QuickRep1.Prepare;
      if QuickRep1.QRPrinter.PageCount>1 then
      begin
        for i:=0 to QRBand1.ControlCount-1 do
        begin
          if QRBand1.Controls[i] is TQRDBText then
             TQRDBText(QRBand1.Controls[i]).Font.Size:=TQRDBText(QRBand1.Controls[i]).Font.Size-1;
         end;
        QuickRep1.Prepare;
      end;
      QuickRep1.Preview;
    end;