有人遇到过使用delphi自带的QReport报表只能打印第一页和最后一页的问题吗?

时间:2022-04-30 19:13:13
我使用delphi自带的报表控件,可是在打印时,本来有8页的报表,却只能打印出第一页
和最后一页。

请各位高手给我讲一下是什么问题,万分感激。可以会贴,也可发到我的油箱:
cpage@263.net  

全部可用分相赠,绝不食言.谢谢

本来发到报表类的,可是那边人气太底,没人看

3 个解决方案

#1


代码如下:///报表窗口,自己没有写代码,就是放了几个控件。
///不知道是否在换页时要写代码?请各位高手指点
unit repLogFrm;

interface

uses Windows, SysUtils, Messages, Classes, Graphics, Controls,
  StdCtrls, ExtCtrls, Forms, Quickrpt, QRCtrls;

type
  TrepLog = class(TQuickRep)
    ColumnHeaderBand1: TQRBand;
    DetailBand1: TQRBand;
    TitleBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRLabel2: TQRLabel;
    QRDBText1: TQRDBText;
    QRDBText2: TQRDBText;
    QRDBText3: TQRDBText;
    QRDBText4: TQRDBText;
    QRLabel3: TQRLabel;
    QRLabel4: TQRLabel;
    QRLabel5: TQRLabel;
    QRLabel6: TQRLabel;
    QRLabel7: TQRLabel;
    QRSysData1: TQRSysData;
    PageFooterBand1: TQRBand;
    QRSysData2: TQRSysData;
    QRSysData3: TQRSysData;
  private

  public

  end;

var
  repLog: TrepLog;

implementation

uses loginDataModule;

{$R *.DFM}

end.


///主程序调用
procedure TViewLogForm.btnPrintClick(Sender: TObject);
var
     rep: TrepLog;
     str: string;
begin
     rep := TRepLog.Create(self);
     if FormatDateTime('yyyy',startdate) = '1900' then
           str := '(全部)'
     else
           str := '从 '+datetostr(startdate)+' 到 '+datetostr(enddate);
     rep.QRLabel2.Caption := '[时间段]'+str+'  [操作员] '+cbbUser.Text;
     rep.PreviewModal;
     rep.Free;
end;


请大家帮帮忙,指点我一下,马上给分

#2


你将QReport控件放在TQRpreview控件中来使用,在TQRpreview中添加打印按钮和其它翻页功能按钮,应该不会有问题。以下是我的一些代码,可以参考一下。
unit frmPreview;

interface

uses
 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, ToolWin, QRPrntr, ExtCtrls, Buttons, Menus;

type
  TxtPreviewForm = class(TForm)
    QRPreview1: TQRPreview;
    Panel1: TPanel;
    StatusBar1: TStatusBar;
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    PopupMenu1: TPopupMenu;
    N1001: TMenuItem;
    N1101: TMenuItem;
    N1201: TMenuItem;
    N1501: TMenuItem;
    N2001: TMenuItem;
    SpeedButton8: TSpeedButton;

    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure QRPreview1PageAvailable(Sender: TObject; PageNum: Integer);
    procedure FormCreate(Sender: TObject);
    procedure SetPageNumber(PageNumber: Integer);
    procedure SetZoom(Zoom: Integer);

    procedure SpeedButton7Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure QRPreview1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton8Click(Sender: TObject);
    procedure N1001Click(Sender: TObject);
    procedure N1101Click(Sender: TObject);
    procedure N1201Click(Sender: TObject);
    procedure N1501Click(Sender: TObject);
    procedure N2001Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    PageCount:Integer;
  end;

var
  xtPreviewForm: TxtPreviewForm;
implementation

uses reportxunjian, pbreport;

{$R *.DFM}







procedure TxtPreviewForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 try
   QRPreview1.QRPrinter.Free;
   QRPreview1.QRPrinter:=nil;
 except
 end;
   action:=cafree;
end;

procedure TxtPreviewForm.QRPreview1PageAvailable(Sender: TObject;
  PageNum: Integer);
begin
PageCount:=PageNum;
  StatusBar1.Panels[1].Text:='第'+IntToStr(QRPreview1.PageNumber)+'页    共'+IntToStr(PageCount)+'页';
  case QRPreview1.QRPrinter.Status of
    mpReady: StatusBar1.Panels[0].Text:='待用...';
    mpBusy: StatusBar1.Panels[0].Text:='正在处理...';
    mpFinished: StatusBar1.Panels[0].Text:='完成';
  end;
  QRPreview1.Zoom:=100;
  SetZoom(QRPreview1.Zoom);
end;

procedure TxtPreviewForm.FormCreate(Sender: TObject);
begin
PageCount:=0;
end;

procedure TxtPreviewForm.SetPageNumber(PageNumber: Integer);
begin
QRPreview1.PageNumber:=PageNumber;
  StatusBar1.Panels[1].Text:='第'+IntToStr(QRPreview1.PageNumber)+'页    共'+IntToStr(PageCount)+'页';
end;

procedure TxtPreviewForm.SetZoom(Zoom: Integer);
begin
StatusBar1.Panels[2].Text:=IntToStr(Zoom)+'%';
end;

procedure TxtPreviewForm.SpeedButton7Click(Sender: TObject);
begin
   SetPageNumber(1);
end;

procedure TxtPreviewForm.SpeedButton4Click(Sender: TObject);
begin
  SetPageNumber(QRPreview1.PageNumber-1);
end;

procedure TxtPreviewForm.SpeedButton6Click(Sender: TObject);
begin
    SetPageNumber(QRPreview1.PageNumber+1);
end;

procedure TxtPreviewForm.SpeedButton3Click(Sender: TObject);
begin
    SetPageNumber(QRPreview1.QRPrinter.PageCount);
end;

procedure TxtPreviewForm.SpeedButton2Click(Sender: TObject);
begin
     QRPreview1.QRPrinter.PrintSetup;  
end;

procedure TxtPreviewForm.SpeedButton1Click(Sender: TObject);
begin
    QRPreview1.QRPrinter.Print;  
end;

procedure TxtPreviewForm.SpeedButton5Click(Sender: TObject);
begin
   Close;
end;

procedure TxtPreviewForm.QRPreview1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Case Button of
    mbLeft:QRPreview1.Zoom:=QRPreview1.Zoom+10;
    mbRight:
    if QRPreview1.zoom>100 then
    QRPreview1.Zoom:=QRPreview1.Zoom-10;
  end;
  SetZoom(QRPreview1.Zoom);
end;

procedure TxtPreviewForm.SpeedButton8Click(Sender: TObject);
var
p:TPoint;
begin
p := SpeedButton8.ClientToScreen(Point(0,SpeedButton8.Height));
  PopupMenu1.Popup(p.x,p.y);
end;

procedure TxtPreviewForm.N1001Click(Sender: TObject);
begin
QRPreview1.zoom:=100;
setzoom(100);
end;

procedure TxtPreviewForm.N1101Click(Sender: TObject);
begin
QRPreview1.zoom:=110;
setzoom(110);
end;

procedure TxtPreviewForm.N1201Click(Sender: TObject);
begin
QRPreview1.zoom:=120;
setzoom(120);
end;

procedure TxtPreviewForm.N1501Click(Sender: TObject);
begin
QRPreview1.zoom:=150;
setzoom(150);
end;

procedure TxtPreviewForm.N2001Click(Sender: TObject);
begin
QRPreview1.zoom:=200;
setzoom(200);
end;

procedure TxtPreviewForm.FormDestroy(Sender: TObject);
begin
  self:=nil;
end;

end.

#3


非常感谢,我先拷回去试一下

#1


代码如下:///报表窗口,自己没有写代码,就是放了几个控件。
///不知道是否在换页时要写代码?请各位高手指点
unit repLogFrm;

interface

uses Windows, SysUtils, Messages, Classes, Graphics, Controls,
  StdCtrls, ExtCtrls, Forms, Quickrpt, QRCtrls;

type
  TrepLog = class(TQuickRep)
    ColumnHeaderBand1: TQRBand;
    DetailBand1: TQRBand;
    TitleBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRLabel2: TQRLabel;
    QRDBText1: TQRDBText;
    QRDBText2: TQRDBText;
    QRDBText3: TQRDBText;
    QRDBText4: TQRDBText;
    QRLabel3: TQRLabel;
    QRLabel4: TQRLabel;
    QRLabel5: TQRLabel;
    QRLabel6: TQRLabel;
    QRLabel7: TQRLabel;
    QRSysData1: TQRSysData;
    PageFooterBand1: TQRBand;
    QRSysData2: TQRSysData;
    QRSysData3: TQRSysData;
  private

  public

  end;

var
  repLog: TrepLog;

implementation

uses loginDataModule;

{$R *.DFM}

end.


///主程序调用
procedure TViewLogForm.btnPrintClick(Sender: TObject);
var
     rep: TrepLog;
     str: string;
begin
     rep := TRepLog.Create(self);
     if FormatDateTime('yyyy',startdate) = '1900' then
           str := '(全部)'
     else
           str := '从 '+datetostr(startdate)+' 到 '+datetostr(enddate);
     rep.QRLabel2.Caption := '[时间段]'+str+'  [操作员] '+cbbUser.Text;
     rep.PreviewModal;
     rep.Free;
end;


请大家帮帮忙,指点我一下,马上给分

#2


你将QReport控件放在TQRpreview控件中来使用,在TQRpreview中添加打印按钮和其它翻页功能按钮,应该不会有问题。以下是我的一些代码,可以参考一下。
unit frmPreview;

interface

uses
 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, ToolWin, QRPrntr, ExtCtrls, Buttons, Menus;

type
  TxtPreviewForm = class(TForm)
    QRPreview1: TQRPreview;
    Panel1: TPanel;
    StatusBar1: TStatusBar;
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    PopupMenu1: TPopupMenu;
    N1001: TMenuItem;
    N1101: TMenuItem;
    N1201: TMenuItem;
    N1501: TMenuItem;
    N2001: TMenuItem;
    SpeedButton8: TSpeedButton;

    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure QRPreview1PageAvailable(Sender: TObject; PageNum: Integer);
    procedure FormCreate(Sender: TObject);
    procedure SetPageNumber(PageNumber: Integer);
    procedure SetZoom(Zoom: Integer);

    procedure SpeedButton7Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure QRPreview1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton8Click(Sender: TObject);
    procedure N1001Click(Sender: TObject);
    procedure N1101Click(Sender: TObject);
    procedure N1201Click(Sender: TObject);
    procedure N1501Click(Sender: TObject);
    procedure N2001Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    PageCount:Integer;
  end;

var
  xtPreviewForm: TxtPreviewForm;
implementation

uses reportxunjian, pbreport;

{$R *.DFM}







procedure TxtPreviewForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 try
   QRPreview1.QRPrinter.Free;
   QRPreview1.QRPrinter:=nil;
 except
 end;
   action:=cafree;
end;

procedure TxtPreviewForm.QRPreview1PageAvailable(Sender: TObject;
  PageNum: Integer);
begin
PageCount:=PageNum;
  StatusBar1.Panels[1].Text:='第'+IntToStr(QRPreview1.PageNumber)+'页    共'+IntToStr(PageCount)+'页';
  case QRPreview1.QRPrinter.Status of
    mpReady: StatusBar1.Panels[0].Text:='待用...';
    mpBusy: StatusBar1.Panels[0].Text:='正在处理...';
    mpFinished: StatusBar1.Panels[0].Text:='完成';
  end;
  QRPreview1.Zoom:=100;
  SetZoom(QRPreview1.Zoom);
end;

procedure TxtPreviewForm.FormCreate(Sender: TObject);
begin
PageCount:=0;
end;

procedure TxtPreviewForm.SetPageNumber(PageNumber: Integer);
begin
QRPreview1.PageNumber:=PageNumber;
  StatusBar1.Panels[1].Text:='第'+IntToStr(QRPreview1.PageNumber)+'页    共'+IntToStr(PageCount)+'页';
end;

procedure TxtPreviewForm.SetZoom(Zoom: Integer);
begin
StatusBar1.Panels[2].Text:=IntToStr(Zoom)+'%';
end;

procedure TxtPreviewForm.SpeedButton7Click(Sender: TObject);
begin
   SetPageNumber(1);
end;

procedure TxtPreviewForm.SpeedButton4Click(Sender: TObject);
begin
  SetPageNumber(QRPreview1.PageNumber-1);
end;

procedure TxtPreviewForm.SpeedButton6Click(Sender: TObject);
begin
    SetPageNumber(QRPreview1.PageNumber+1);
end;

procedure TxtPreviewForm.SpeedButton3Click(Sender: TObject);
begin
    SetPageNumber(QRPreview1.QRPrinter.PageCount);
end;

procedure TxtPreviewForm.SpeedButton2Click(Sender: TObject);
begin
     QRPreview1.QRPrinter.PrintSetup;  
end;

procedure TxtPreviewForm.SpeedButton1Click(Sender: TObject);
begin
    QRPreview1.QRPrinter.Print;  
end;

procedure TxtPreviewForm.SpeedButton5Click(Sender: TObject);
begin
   Close;
end;

procedure TxtPreviewForm.QRPreview1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Case Button of
    mbLeft:QRPreview1.Zoom:=QRPreview1.Zoom+10;
    mbRight:
    if QRPreview1.zoom>100 then
    QRPreview1.Zoom:=QRPreview1.Zoom-10;
  end;
  SetZoom(QRPreview1.Zoom);
end;

procedure TxtPreviewForm.SpeedButton8Click(Sender: TObject);
var
p:TPoint;
begin
p := SpeedButton8.ClientToScreen(Point(0,SpeedButton8.Height));
  PopupMenu1.Popup(p.x,p.y);
end;

procedure TxtPreviewForm.N1001Click(Sender: TObject);
begin
QRPreview1.zoom:=100;
setzoom(100);
end;

procedure TxtPreviewForm.N1101Click(Sender: TObject);
begin
QRPreview1.zoom:=110;
setzoom(110);
end;

procedure TxtPreviewForm.N1201Click(Sender: TObject);
begin
QRPreview1.zoom:=120;
setzoom(120);
end;

procedure TxtPreviewForm.N1501Click(Sender: TObject);
begin
QRPreview1.zoom:=150;
setzoom(150);
end;

procedure TxtPreviewForm.N2001Click(Sender: TObject);
begin
QRPreview1.zoom:=200;
setzoom(200);
end;

procedure TxtPreviewForm.FormDestroy(Sender: TObject);
begin
  self:=nil;
end;

end.

#3


非常感谢,我先拷回去试一下