How to catch exception in report export (file already open)

hsmhsm
edited 8:57AM in FastReport 3.0
In Delphi (2009) I'm using these lines to export a report under code

frxReport1.PrepareReport;
frxReport1.Export(frxXMLExport1);

This works OK but obviously raises an exception if the filename used for export is already open in Excel.

To get round this I tried using a try-except block like below but frxReport1.Export seems to cause a system wide exception first, before delphi can catch it and so kills my program.

How can I generate a more user friendly message if the export causes an exception and allow the user to try a different filename?

This is the code I used to try to handle the exception

try
frxReport1.PrepareReport;
frxReport1.Export(frxXMLExport1); // if there is an exception in here, the 'on e.exception' code never gets a chance to run

except

on e: exception do
begin
ShowMessage('Failed to save ' + frxXMLExport1.Filename +slinebreak + slinebreak +
'Are you sure you don''t already have this file open in Excel?');
filesaved := false;
end;

end;

Comments

  • gpigpi
    edited 8:57AM
    Try to analize TfrxReport.Errors after export

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.