{this event is not fired} procedure TFrame1.ppReportMainPrintDialogClose(Sender: TObject); begin if ppReportMain.PrintDialog.ModalResult = mrOK then begin ShowMessage('OK'); end else begin ShowMessage('Cancel'); end; end;
If you are loading templates, there is a good chance you are loosing the report's reference to the event handler code you wrote. Check out the article below for more information on lost event handlers. You may need to re-assign the property event hander code in the Template event OnLoadEnd for an easy work around.
-------------------------------------------- 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:
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:
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.
Comments
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;
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I have tried your example, but the Report.OnPrintDialogClose event is not
fired.
My code:
procedure TFrame1.ActionPrintExecute(Sender: TObject);
begin
ppReportMain.Template.LoadFromFile;
ppReportMain.ShowPrintDialog := True;
ppReportMain.ShowCancelDialog := True;
ppReportMain.AllowPrintToFile := false;
ppReportMain.DeviceType := dtPrinter;
ppReportMain.Print;
ppReportMain.ShowPrintDialog := false;
ppReportMain.DeviceType := dtScreen;
ppReportMain.PrintToDevices;
end;
....
...
{this event is not fired}
procedure TFrame1.ppReportMainPrintDialogClose(Sender: TObject);
begin
if ppReportMain.PrintDialog.ModalResult = mrOK then begin
ShowMessage('OK');
end
else begin
ShowMessage('Cancel');
end;
end;
What can I do?
Best regards,
Dmitri
If you are loading templates, there is a good chance you are loosing the
report's reference to the event handler code you wrote. Check out the
article below for more information on lost event handlers. You may need to
re-assign the property event hander code in the Template event OnLoadEnd for
an easy work around.
--------------------------------------------
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.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
thank you very much, it works now!
Dmitri