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

hsmhsm
edited 10:50AM 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 10:50AM
    Try to analize TfrxReport.Errors after export

Leave a Comment