Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Access Violation when closing after printing

edited June 2004 in General
Hi,

I have a form which I allow users to select different report criteria.
If the user chooses to print to the printer, or to a file, i want to close
the form when printing is complete.
When I try this I get an Access Violation. If I try to close after a
preview, it's fine.
I have verified that the close is taking place after the OnAfterPrint and
onPrintingComplete events.

Does anyone have any suggestions?

Thanks,
Rick Gerrits
Accu-Med Services, LLC

Comments

  • edited June 2004
    By the way:
    I'm using RB 7.03 pro with Delphi 7 Enterprise, on Windows 2000.
  • edited June 2004
    Hi,

    You need to be sure you are closing the form after the report has finished
    printing, and freeing all its references. The best place to do this is
    after the call to Report.Print. See the example below on how to do this.

    http://www.digital-metaphors.com/tips/FormDestroy.zip

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2004
    Thanks for the quick response Nico.
    I am actually trying to close after the Report.Print method.
    To be more clear about my issue, my report and form that I print from are in
    a BPL.
    Do you have any examples of using Rbuilder in a BPL? I seem to be stuck.

    Thanks.

    Rick
  • edited June 2004
    Hi,

    The fact that your report and form are in a package should not make a
    difference in the code executed. If you compile without packages, does your
    application work correctly?

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2004
    Hi,

    Thanks for the help, but I'm still getting the issue.
    I put together a small demo of what's going on. My problem very well could
    be related to
    how I'm unloading the package but I can't seem to see it...

    In my demo i have a package with a form that has 2 options... prievew/print.
    If you preview, when you close the preview form, the "configuration form"
    closes without problem.
    If you print however, you get an access violation...

    Any ideas?

    Thanks,
    Rick

  • edited June 2004
    Hi Rick,

    Thanks for the example. For future reference, please send all files to
    support@digital-metaphors.com if you would like us to look at an example.

    It looks as though the call to "Close" may be executed too soon for the
    report to finish printing completely. As a test I placed a TTimer on your
    second form and created a 1 second delay after the report.print call and
    before the close call. This seemed to solve the issue. Below is the code I
    added to your Unit2.pas file. You will need to add the declaration of the
    ehTimer event hander in the Interface section and drop a TTimer anywhere on
    your form.

    procedure TForm2.Button1Click(Sender: TObject);
    begin
    DataModule3.ppReport1.AllowPrintToArchive := True;
    DataModule3.ppReport1.Device := dvArchive;
    DataModule3.ppReport1.Print;

    Timer1.Enabled := True;
    end;

    procedure TForm2.FormCreate(Sender: TObject);
    begin
    DataModule3 := TDataModule3.Create(Application);

    Timer1.Enabled := False;
    Timer1.Interval := 1000;
    Timer1.OnTimer := ehTimer
    end;

    procedure TForm2.ehTimer(Sender: TObject);
    begin
    Close;
    end;



    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2004
    Thank you!

This discussion has been closed.