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

AV in rbRCL76.BPL

edited May 2003 in General
I'm upgrading a large application written in D5 using RB 5.53 to D6sp2 using
RB7.02 and I have run into some strange behavior.
When closing a report using our custom print preview form I get an AV in
rbRCL76 then one in VCL60.BPL and the report form is not freed from memory.
If I try to access the report again, I get a message like "A component named
X already exists".

Basically I need to find a correct way to free a report after:
1. Printing directly to the print
2. Previewing the report from the preview screen in an MDI application.

The application is an MDI application. I use our own preview form. This is
the initialization of the preview form:
-----------------------------------
initialization
ppRegisterForm(TppCustomPreviewer, TFrmPreview);
finalization
ppUnRegisterForm(TppCustomPreviewer);
-----------------------------------

when I create the report:
---------------------------------------------------------------
PrintTo = 'SCREEN';
Application.CreateForm(TRepAllergyList, RepAllergyList);

if PrintTo = 'SCREEN' then
RepAllergyList.Report.Device := dvScreen;
else
RepAllergyList.Report.Device := dvPrinter;

RepAllergyList.Report.Print;

if PrintTo = 'PRINTER' then
RepAllergyList.Free; // free the report from memory
{if PrintTo = 'SCREEN' free the report on ReportPreviewFormClose}
-------------------------------------------------------------------

Code from RepAllergyList:
-------------------------------------------------------------------
procedure TRepAllergyList.ReportPreviewFormClose(Sender: TObject);
begin
// free the report from memory
RepAllergyList.Release;
RepAllergyList:=nil;
end;
--------------------------------------------------------------------

Printing the reports to the printer work fine but when I use the print
preview form the report shows & prints fine but when I close the form I get
the AV in rbRCL76 then again in VCL60.BPL and the report form is not freed
from memory.

This code was working fine in D5 with RB 5.53

Any suggestions would be most helpful!

Thanks,
Paul

Comments

  • edited May 2003
    Why would the following cause an A/V in rbRCL76.BPL?




  • edited May 2003
    The A/V are comming in:

    TppCommunicator.Notify and
    TppCustomReport.Notify

    Paul
  • edited May 2003
    Paul,

    If you free the form in the ReportPreviewFormClose event you are freeing it
    too early. When the report tries to exit, it is referencing an object that
    is not there. This is the reason you are receiving the AV errors. You need
    to use a Try/Finally statement around your initial code. Something like the
    following...

    Form := CreateYourForm;

    try
    Report.Print;
    finally
    Form.Free;
    Form := nil;
    end;

    This way the form is always destroyed at the right time.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2003
    Thanks,

    That works for a report going to the printer, but what about a print preview
    form?
    Will the following code work?

    Release;
    ReportForm:=nil;


    Paul



  • edited May 2003
    Hello Nico,

    Just for the fun of it I tried your code. It works for printing to the
    printer only. It does not work when you print to the screen. It draws the
    print preview form and then it immediatly closes the print preview screen.
    I need to find the proper way to free a form when printing to a print
    preview screen.

    Thanks!
    Paul


This discussion has been closed.