home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Demos / Quickrpt / Qr3 / needdata.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  2KB  |  87 lines

  1. { :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.   :: QuickReport 3.0 for Delphi 3.0/4.0/5.0                  ::
  3.   ::                                                         ::
  4.   :: Demo report that is populated by the OnNeedData event   ::
  5.   ::                                                         ::
  6.   :: Copyright (c) 1995-1999 QuSoft AS                       ::
  7.   :: All Rights Reserved                                     ::
  8.   ::                                                         ::
  9.   :: web: http://www.qusoft.com  fax: +47 22 41 74 91        ::
  10.   ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: }
  11. unit needdata;
  12.  
  13. interface
  14.  
  15. uses
  16.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  17.   ExtCtrls, QuickRpt, Qrctrls;
  18.  
  19. type
  20.   TfrmNeedData = class(TForm)
  21.     QuickRep1: TQuickRep;
  22.     DetailBand1: TQRBand;
  23.     QRLabel1: TQRLabel;
  24.     TitleBand1: TQRBand;
  25.     QRSysData1: TQRSysData;
  26.     procedure FormCreate(Sender: TObject);
  27.     procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
  28.       var PrintReport: Boolean);
  29.     procedure QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
  30.   private
  31.     { Private declarations }
  32.     SomeList: TStringlist;
  33.     CurrentIndex: integer;
  34.   public
  35.     { Public declarations }
  36.   end;
  37.  
  38. var
  39.   frmNeedData: TfrmNeedData;
  40.  
  41. implementation
  42.  
  43. {$R *.DFM}
  44.  
  45. procedure TfrmNeedData.FormCreate(Sender: TObject);
  46. var
  47.   i: integer;
  48. begin
  49.   SomeList := TStringlist.Create;
  50.  
  51.   for i := 0 to 500 do
  52.     SomeList.Add('Line ' + IntToStr(i));
  53. end;
  54.  
  55. procedure TfrmNeedData.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  56.   var PrintReport: Boolean);
  57. begin
  58.   // You must reset your data in the BeforePrint event
  59.   // or when you print from the preview, the report will
  60.   // start with the last value(s)
  61.   CurrentIndex := 0;
  62. end;
  63.  
  64. procedure TfrmNeedData.QuickRep1NeedData(Sender: TObject;
  65.   var MoreData: Boolean);
  66. begin
  67.   // If MoreData is true, then QuickReport will print
  68.   // another detail band.  When you set it to false,
  69.   // the report is done.  
  70.  
  71.   MoreData := (CurrentIndex < SomeList.Count);
  72.  
  73.   if MoreData then
  74.   begin
  75.     QRLabel1.Caption := SomeList[CurrentIndex];
  76.  
  77.     // Here's how to set the progress bar
  78.     QuickRep1.QRPrinter.Progress := (Longint(CurrentIndex) * 100) div SomeList.Count;
  79.   end
  80.   else
  81.     QuickRep1.QRPrinter.Progress := 100;
  82.  
  83.   Inc(CurrentIndex);
  84. end;
  85.  
  86. end.
  87.