How to tell if a report has actually been printed?
Hi Team,
Given the following code..
{code}
with ReportsFrm.ReportsForm do
begin
ppRE1.LoadReport('Tax Quote', 2);
ppR1.ShowAutoSearchDialog := False;
ppR1.AutoSearchFields[0].SearchExpression := sJobNo;
ppR1.Print;
end;
{code}
Where/how can I tell if the 'report' has actually been printed rather than just viewed and closed?
Regards & TIA,
Ian
Given the following code..
{code}
with ReportsFrm.ReportsForm do
begin
ppRE1.LoadReport('Tax Quote', 2);
ppR1.ShowAutoSearchDialog := False;
ppR1.AutoSearchFields[0].SearchExpression := sJobNo;
ppR1.Print;
end;
{code}
Where/how can I tell if the 'report' has actually been printed rather than just viewed and closed?
Regards & TIA,
Ian
This discussion has been closed.
Comments
Take a look at the following article on how to detect if the report has
been printed to the printer.
http://www.digital-metaphors.com/rbWiki/Output/Printer/Detecting_Whether_Report_Printed_to_Printer
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for the pointer and I suspect it will do the job however it doesn't seem to work in my configuration..
To clarify further..
1. Win 10, D10.2, latest RB.
2. ppR1 and associated components, designer, explorer, etc are in what is in effect the end-user form.
ReportsFrm.ReportsForm.
3. The calling code, shown in the previous message, is in another form, both part of the main App. MainForm.
4. The prints are always previewed before manually printing. This is to allow a final check that all details are
correct.
5. I added the "if ppR1.PrinterDevice <> nil then ShowMessage('Report was printed to the printer');" to the
TReportsForm.ppR1AfterPrint(Sender: TObject);. IIUC it should show whenever anything is actually printed by ppR1.
Unfortunately it doesn't. Not sure at what time after printing the routine is called but using F4 to trace to the
AfterPrint procedure, it never gets there.
Thoughts?
Regards,
Ian
Looking at your initial message it appears you are perhaps loading
templates. If so, you are loosing the event reference when the template
is loaded.
http://www.digital-metaphors.com/rbWiki/Design/Templates/How_To...Troubleshoot_Lost_Event_Handlers
One solution is to use RAP. Another is to assign the event handler
after the report has been loaded.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Again, thanks for the pointer.
I ended up with a version of the following.....
{code}
...
...
procedure TJobTicketsForm.ReportPrinted(Sender: TObject);
begin
if ReportsFrm.ReportsForm.ppR1.PrinterDevice <> nil then ShowMessage('Report was printed to the printer');
end;
...
...
with ReportsFrm.ReportsForm do
begin
ppRE1.LoadReport('Sales Invoice', 2);
ppR1.ShowAutoSearchDialog := False;
ppR1.AutoSearchFields[0].SearchExpression := sJobNo;
ppR1.AfterPrint := ReportPrinted;
ppR1.Print;
end;
...
..
{code}
Works perfectly thank you.
Regards,
Ian
In a couple of my applications it's essential that a report was fully
printed, and actually went to a printer:
//---EJB---2005.08.28-----------------------------
procedure TfrmRepPSIView.ppReport1PrintDialogClose(Sender: TObject);
begin
// we accept only snet to printer, but NOT if printtofile
FSentToPrinter:= ( (ppReport1.PrintDialog.DeviceType='Printer') and
not (ppReport1.PrintDialog.PrintToArchive) and
not (ppReport1.PrintDialog.PrintToFile)
);
end;
And it had to be the complete range of pages:
//---EJB---2005.08.29-----------------------------
function TfrmRepPSIView.WasSentToPrinterEx: Boolean;
begin
// not only sent to printer, but EVERYTHING sent to printer
result:=(FSentToPrinter and (FPgSetting=psAll) and (FPgRange=prAll));
end;
Here's where I populate FPgSetting and FPgRange...
FPgSetting : TppPageSettingType;
FPgRange : TppPageRangeType;
//---EJB---2005.08.28-----------------------------
procedure TfrmRepPSIView.ResetPrintStateFlags;
// call before starting a print job
begin
FPgSetting := psFirstPage; // force to anything but "all" so we
default to false
FPgRange := prOddPages; // force to anything but "all" so we
default to false
FUserCancelled := False; // assume print not cancel
FSentToPrinter := False; // assume not sent to printer
end;
//---EJB---2005.08.29-----------------------------
procedure TfrmRepPSIView.ppReport1PageRequest(Sender,
aPageRequest: TObject);
begin
if Assigned(ppReport1.PrintDialog) then begin
FPgSetting:= TppPageRequest( aPageRequest ).PageSetting;
FPgRange := TppPageRequest( aPageRequest ).PageRange;
end;
end;
Interesting.. I don't need it att but I have filed it away for future reference.
Regards & Tks,
Ian
I don't recall if it was Nard or Nico who helped me sort that out a
dozen years ago, but I'm very happy to share it.
I should add that it has worked (unchanged) in every version of RB from
2005 to the latest ver 18.
I love non-breaking upgrades!
EdN
Hear Hear!