Print to file with file open crashes app
When I choose print to file and the output file is open in another
application ReportBuilder crashes my app. For example if the user selects
export to XLS data file and the file is open already in excel then my app
will crash. I'm wondering where is a good place to put a try..except block
so I can catch this error and display a dialog instead of crashing the app?
Thanks in advance,
Rodger Van Kirk
application ReportBuilder crashes my app. For example if the user selects
export to XLS data file and the file is open already in excel then my app
will crash. I'm wondering where is a good place to put a try..except block
so I can catch this error and display a dialog instead of crashing the app?
Thanks in advance,
Rodger Van Kirk
This discussion has been closed.
Comments
Rodger Van Kirk
I'm a bit unclear about what you mean by "crashes my app". Does your
application stop working and quit or are you getting an EFCreateError or
EPrintError exception. Getting these exceptions is the default behavior
while debugging in the Delphi IDE. When running your application as a stand
alone exe or dll, you can suppress these exceptions by placing a
try...except around the Report.Print command and check for this type of
exception being thrown.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
MadException and an EPrintError exception is being fired off. I will try a
try..except around the .Print call and see if it takes care of it.
Thanks,
Rodger Van Kirk
also tried the try..except arount the .Print and it still happened.
Regards,
Rodger Van Kirk
What exactly would you like to happen in this case? Would you like your own
personal message to display or would you like the user to simply see no
error and move on? I assume you have something like the following...
try
Report.Print;
except
on E: EPrintError do
ShowMessage('File Already Open');
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
ShowMessage(E.Message);
I would like to display some kind of message to the user so they can fix the
issue and try again.
Thanks in advance,
Rodger Van Kirk
In your application with the try...except around the Print command, are you
then receiving two messages when you run from a stand-alone exe? In my
testing, I am just getting a single message (the ShowMessage that I
created).
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Could it be because I have set my modalPreview to false? I see the code has
pasted the try..except well before I ever even try to print to file.
Thanks in advance,
Rodger Van Kirk
Yes, printing from the preview will prevent the exception from being
intercepted.
Another option would be to use a report event such as the
Report.OnPrintDialogClose to first check if the file is open, then show a
message and cancel if so. Something like the following...
Note: The IsFileInUse is a routine you write to check if the file is open or
not.
procedure TForm1.ppReport1PrintDialogClose(Sender: TObject);
begin
if IsFileInUse(ppReport1.PrintDialog.TextFileName) then
begin
ShowMessage('File In Use');
ppReport1.PrintDialog.ModalResult := mrCancel;
end;
end;
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
"Rodger Van Kirk" wrote in message news:4ccf2fee$1@mail....
I keep trying to determine why my try..except is not catching the exception.
Could it be because I have set my modalPreview to false? I see the code has
pasted the try..except well before I ever even try to print to file.
Thanks in advance,
Rodger Van Kirk
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com