frxreport.export() : result is dummy?

Hello,

I am facing this problem (D XE2, FR VCL6): when exporting a report to PDF using frxreport.export(), this function does not return a usable result - it does not tell me, whether this export file was saved successfully.

On the other hand, the internal routine for export() is made safe by an try...except, that is why my own outside try...except block does not fire when the file could not be saved.

Has anyone an idea how to solve this problem?

Comments

  • Hello,

    You need to call PrepareReport before Export method and build the report first.


    If Report.PrepareReport then

     Report.Export(ExportFilter);


    Also Export return a result of export process (True if it was successful) and write all errors to Report.Errors.

    So you always can check for errors like that (and even raise an exception if you need one):


    If Report.PrepareReport then

     if not Report.Export(ExportFilter) then

      raise Exception.Create(Report.Errors.Text);

  • Hello,

    I tried this proposal, but it did not work for me - Export() does not return False in case of problems.

    While exporting the PDF file, where a locked version of this file already exists, the debugger shows an exception EFCreateError, but Export() returns True anyway.

    Any further tips?

  • Just checked this code and it works as expected.

    When file is locked it generates EFCreateError exception and show error or re-throw it (depends on engine settings).

    If you have a test case which produce behavior when in case of exception it does not throw an error , please open a support ticket with a test case.

  • I unfortunately forgot to tell you, that I am using the Synopse PDF filter along with FastReport.

    Meanwhile I found the function SaveToFile (see below) in unit SynPDF to be my problem: here the try..except block does not work at an EFCreateError (even when the internal debugger shows this error), and additionally the return value of this function is not interpreted in the calling procedure. I made some small changes, which seem sufficient for me (preset result:=false on beginning of SaveToFile, and raising an exception in the calling procedure if result=false).

    Thank you for your help!


    Source of problem:

    function TPdfDocument.SaveToFile(const aFileName: TFileName): boolean;

    var FS: TFileStream;

    begin

     try

       FS := TFileStream.Create(aFileName,fmCreate);

       try

         SaveToStream(FS);

         result := true;

       finally

         FS.Free;

       end;

     except

       on E: Exception do // error on file creation (opened in reader?)

         result := false;

     end;

    end;

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.