Recent

Author Topic: Print frCompositeReport  (Read 442 times)

cpalx

  • Hero Member
  • *****
  • Posts: 729
Print frCompositeReport
« on: July 22, 2022, 11:44:02 pm »
Hello, i have problem ti print frCompositeReport.

I have a function that works perfectly pinting frReports (function below) but i have now  a frCompositeReport that i need to print,
How can i change this function to able to print frCompositeReports

I changed var TheReport: TfrReport to var TheReport: TfrCompositeReport;

but when execute, send: Access Violation

Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. procedure PrintReport( var TheReport: TfrReport; iCopies: ShortInt);
  4. var
  5.    iFromPage,
  6.    iToPage,
  7.    NumberCopies: Integer;
  8.    ind: Integer;
  9.    Collap: Boolean;
  10. begin
  11.  
  12.  if not TheReport.PrepareReport then Exit;
  13.  // Set up dialog with some sensible defaults which user can change
  14.  with TPrintDialog.Create( nil ) do begin
  15.    Options:=[poPageNums ]; // allows selecting pages/page numbers
  16.    Copies:= iCopies;
  17.    Collate:=true; // ordened copies
  18.    iFromPage:=1; // start page
  19.    iToPage:= TheReport.EMFPages.Count; // last page
  20.    MaxPage:= TheReport.EMFPages.Count; // maximum allowed number of pages
  21.    if Execute then begin// show dialog; if succesful, process user feedback
  22.      if (Printer.PrinterIndex <> ind ) // verify if selected printer has changed
  23.        or TheReport.CanRebuild // ... only makes sense if we can reformat the report
  24.        or TheReport.ChangePrinter(ind, Printer.PrinterIndex) then //... then change printer
  25.        TheReport.PrepareReport //... and reformat for new printer
  26.      else
  27.        exit; // we couldn't honour the printer change
  28.  
  29.      if PrintRange = prPageNums then begin// user made page range selection
  30.        iFromPage:=FromPage; // first page
  31.        iToPage:=ToPage;  // last page
  32.      end;
  33.      NumberCopies:=Copies; // number of copies
  34.      // Print the report using the supplied pages & copies
  35.      TheReport.PrintPreparedReport( IntToStr( iFromPage ) + '-' + IntToStr( ToPage ), NumberCopies );
  36.    end;
  37.    Free;
  38.  end;
  39. end;                                      
  40.  


Tested on windows 11, KdeNeon
Lazarus 2.2.2

korba812

  • Sr. Member
  • ****
  • Posts: 307
Re: Print frCompositeReport
« Reply #1 on: July 23, 2022, 01:19:38 am »
You need to add some reports to the TfrCompositeReport.Reports list. Don't use TfrCompositeReport as a report - don't load lfr form data into it as it will be ignored anyway. Place your reports in separate TfrReport components and add them to the TfrCompositeReport.Reports list. See the attached example.

cpalx

  • Hero Member
  • *****
  • Posts: 729
Re: Print frCompositeReport
« Reply #2 on: July 23, 2022, 03:26:46 pm »
Hello, of course i add some reports to composit:
For example:

Code: Pascal  [Select][+][-]
  1. for i:=0 to Length(Reportes) - 1 do begin
  2.    Reportes[ i  ]:= TfrReport.Create( Self );
  3.    Reportes[ i ].LoadFromFile( FilePersonReport );
  4.     frCompositeReport1.Reports.Add( Reportes[ i ] );
  5.  end;              
  6.  

korba812

  • Sr. Member
  • ****
  • Posts: 307
Re: Print frCompositeReport
« Reply #3 on: July 23, 2022, 03:55:50 pm »
I added your code to my example and I am unable to replicate this problem. Can you check where the exception is coming from (run in debugger or create a stack trace)?

cpalx

  • Hero Member
  • *****
  • Posts: 729
Re: Print frCompositeReport
« Reply #4 on: July 23, 2022, 06:59:06 pm »
My fault, y was destroying my frReports Array before print

 

TinyPortal © 2005-2018