views:

219

answers:

1

I'm using FastReport 4.7.31 in Turbo Delphi Pro.

The following procedure processes the data stored in several dated files depending on user input.

    procedure TfrmMain.MyReportPrint;
var  MDate : Tdate;
     S, myfile : string;
     firstone: boolean;
//   Date1, Date2 & ShowPreview are global variables set via a dialog box     
begin
   firstone := true;
   MDate := Date1;
   while MDate < IncDay(Date2, 1)  do
   begin
      DateTimeToString(S,'yyyymmdd',MDate);
      myfile := 'm' + S + '.dbf';
      if FileExists(DataPath + '\' + myfile) then
      begin
         tblPS.Close;
         tblPS.TableName := myfile;
         frxMyReport.PrepareReport(firstone);
         firstone := false;
      end;
      MDate := IncDay(MDate, 1);
   end;
   if ShowPreview then frxMyReport.ShowReport else frxMyReport.Print;
end;

frxMyReport.Print prints all the pages.

frxMyReport.ShowReport shows only the last page prepared.

+3  A: 

The ShowReport method takes an optional parameter ClearLastReport, and its default value is true. Whether it's true or false, ShowReport prepares the report before displaying it, so in your code, you're discarding everything you've already prepared and then re-preparing the report using the most recently assigned table settings. If the only change you were to make to your code would be to pass False to ShowReport, then you'd find that the preview showed all your pages, but repeated the last page.

In contrast to ShowReport, the Print method does not prepare the report. It only prints what has already been prepared. You want ShowPreparedReport for your preview, not ShowReport. See section 1.9 of the FastReport Programmer's Manual.

Rob Kennedy