Home End User
New Blog Posts: Merging Reports - Part 1 and Part 2

Cancel printing

edited May 2004 in End User
HI I have some problems with cancelling print jobs.

1. I have the following code, but it is completely ignored, even the 'OK'
doesn't show.
I am assuming that this is the "Cancel" button on the message saying
printing page 1 etc. and not the printer selection dialog.
procedure TfmContact_LetterPrn.ppReport1CancelDialogClose(Sender: TObject);
begin

ShowMessage('OK');

if ppReport1.PrintDialog.ModalResult = mrCancel then
begin
ShowMessage('Use chose to cancel the print request');
bPrintJobCancelled := true ;
end;

end;

2. When you click "Cancel" on the print dialog box, is there any way of
detecting this so that the procedures that follow are not performed, e.g
setting a printed flag from yes to no should open happen if the printing
actually happens.

Thanks

Andy Dyble
D5, RB7Ent.

Comments

  • edited May 2004
    This is also ignored :

    procedure TForm1.ppReport1Cancel(Sender: TObject);
    begin
    ShowMessage('Printing cancelled by user');

    end;


    Andy


  • edited May 2004
    More info.

    Even this is ignored :

    procedure TfmContact_LetterPrn.ppReport1PrintDialogClose(Sender: TObject);
    begin

    showmessage('ok');

    end;

    Is there a genral setting I have missed ?

    Thanks


    Andy
  • edited May 2004
    Hi Andy,

    If you are loading templates in your application, that may be the reason you
    are loosing your event handler code. Please see the article below on lost
    event handlers.

    --------------------------------------------
    Article: Troubleshooting Lost Event Handlers
    --------------------------------------------

    Let's assume you have created a report in Delphi and assign an event
    handlers to the OnPreviewFormCreate event of the report. The event is
    generated by Delphi as:

    procedure TForm1.ppReport1PreviewFormCreate(Sender: TObject);

    You then save the report to an RTM file 'Report1.RTM.' The events are
    stored as references only, and so the RTM contains:

    object ppReport1: TppReport
    .
    .
    OnPreviewFormCreate = ppReport1PreviewFormCreate
    end

    You then go on to work on a different report. Saving it with under then
    name 'Report2.RTM'. Only this time, before you save the report you
    change the report component name to: rptOrders. Delphi automatically
    updates the event declaration for OnPreviewFormCreate event to:

    procedure TForm1.rptOrdersPreviewFormCreate(Sender: TObject);


    You then create two buttons on the form, one to load Report1 and
    preview, the other to load Report2 and preview. When you run the app
    and click Report1, you an error. This is because the Report1.RTM file
    contains a reference to ppReport1PreviewFormCreate, a method which no
    longer exists (at least with this name) in the form.

    One answer is to load all your rtm files into the report component you
    will be using for loading. Fix any errors, reassign any events that get
    cleared. This will update your rtms to contain the proper event handler
    names.


    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2004
    Nico,
    This assumes I am working on a different report then the one I loaded which
    isn't the case.

    Andy


  • edited May 2004
    Hi Andy,

    Sorry, I must have misread your original post. See the articles below on
    how to detect if the report has been printed to the printer or not.

    ------------------------------------------
    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;

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2004
    Thanks but that doesn't bring up a message either.

    Andy

  • edited June 2004
    Hi Andy,

    Here is an example I just created to show how the method I described below
    works. The events seem to fire correctly.

    http://www.digital-metaphors.com/tips/PrintMessageTest.zip

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.