Hi, when i call TppReport.Print (DeviceType = printer) the print dialog
appeared, but i dunno whether the user click "OK" or "Cancel" in the
print dialog as TppReport.Print doesn't return any status. Is that any
other way to determine ?
Thanks !
From,
Sherlyn Chew
Comments
Take a look at the following articles on the printer dialog.
------------------------------------------
Tech Tip: Detecting whether PrintDialog's
Cancel button was Selected
------------------------------------------
When the print dialog is displayed to the user, you can determine whether
the Cancel button was selected by using the Report.OnPrintDialogClose
event.
Example:
procedure TForm1.ppReport1PrintDialogClose(Sender: TObject);
begin
if ppReport1.PrintDialog.ModalResult = mrCancel then
ShowMessage('Use chose to cancel the print request');
end;
------------------------------------------
Tech Tip: Detecting whether Report was
Printed to the Printer
------------------------------------------
The Report.AfterPrint event can be used to determine whether the report was
printed to the printer (rather than preview, ...).
Example:
procedure TForm1.ppReport1AfterPrint(Sender: TObject);
begin
if (ppReport1.PrinterDevice <> nil) then
ShowMessage('Report was printed to the printer');
end;
Note: If the user cancels the report while it is running, then the
Report.OnCancel event will fire, followed by the Report.AfterPrint event.
Example:
procedure TForm1.ppReport1Cancel(Sender: TObject);
begin
ShowMessage('Printing cancelled by user');
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I tried to use these events now and have some questions.
After the Report.OnCancel event the Report.AfterPrint event fires, which
seems to be not correct in the first moment (since I actually cancelled the
printing), but probably *is* correct, since the report was sent to the
printer. Report.PrinterDevice is <> nil in that case, so according to the
article it would mean, that the report was printed, but ti wasn't yet. It's
still in progress.
Since I cancelled the print command, I would like to cancel the print jobs
too and my question is, how I can do that?
Calling of Report.PrinterDevice.CancelJob; or Report.PrinterDevice.EndJob;
in the Report.OnCancel event doesn't work (in case that are correct methods
to use, of course). So something else needs to be done...
Also there is an issue after cancelling, that the Screen.Cursor remains at
crHourGlass afterwards and it looks, as if something is still in progress,
not executed / terminated or so... Waiting some times doesn't change that.
Any ideas?
So those are the two questions I have at the moment to this topic.
Regards,
Mark
Posting both of those articles at once can be confusing.
The first article refers to whether the user selected the "cancel" button of
the actual printer dialog. The second article is meant to let you know if
the user printed to file or screen rather than the printer. In this case
the "ok" button is selected in the Printer dialog. The bottom part of the
second article shows how to detect if the user selects "cancel" in the
cancel dialog after "ok" has been selected from the printer dialog.
If the device is the actual printer, then the TppPrinterDevice is created
once you select "ok" and printing has begun. Selecting "cancel" after that
attempts to stop report generation (when it finds an opportunity), however
printing has indeed already begun so the AfterPrint event will still fire.
Essentially you cannot use the AfterPrint event to determine whether the
report was canceled or not.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I agree, this can be confusing, but nevertheless I think, that it's in
general about the same topic.
Looking at it again I think, that I can work with that. I just would like to
know, if it's somehow possible to cancel and to remove the actuall print
job(s) from the printer queue?
This may be possible using the Windows API however there is currently no
built-in functionality in ReportBuilder to do so.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I will see what I can do about it. Thank you for the reply.
Mark