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

Access violations for sub-reports after loading end-user report

edited April 2011 in End User
Hi, I've just upgraded to RB Pro 12 and I'm am trying to implement the
end-user reporting module.
I have loaded the report at runtime ok, but there seems to be a problem with
the sub-reports.

My existing code has these objects:
rptGlassOrder: TppReport;
srGlassOrderPanelDetails: TppSubReport;
rptGlassOrderPanelDetails: TppChildReport;
srGlassOrderPanelSummary: TppSubReport;
rptGlassOrderPanelSummary: TppChildReport;
srGlassOrderCutouts: TppSubReport;
rptGlassOrderCutouts: TppChildReport;

Then I load from file:
rptGlassOrder.Template.LoadFromStream(LFileStream); <- OK

However after loading from file, I get an access an access violation when I
try to access any of the sub reports or child report objects.
eg:
rptGlassOrder.PrinterSetup.PaperName := lsPaperName; <- OK
rptGlassOrderPanelDetails.PrinterSetup.PaperName := lsPaperName; <- AV
rptGlassOrderPanelSummary.PrinterSetup.PaperName := lsPaperName; <- AV
rptGlassOrderCutouts.PrinterSetup.PaperName := lsPaperName; <- AV

What am I dong wrong?

Thanks.
Rick.

Comments

  • edited April 2011
    Hi Rick,

    Are these newly created templates or older ones? Where (which event)
    are you trying to access the subreport's properties? If you trace into
    your source where the AV occurs, is the subreport a valid object? If
    possible, try tracing into the RB source to see exactly where the AV is
    occuring.


    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2011
    Rick,

    I see that you posted here and also sent the same question to support@.
    Please post questions to a single destination. :)

    The example code you show produces the result I would expect.

    The report rptGlassOrder is comprised of elements - labels, subreports, etc.
    When you load a template, the elements are destroyed and the elements
    defined in the report template file/stream are instantiated.

    The simplest solution is to use RAP code embedded in the report. Then the
    code is saved with the report definition and can access the elements by
    name. For this you need RB Enterprise.

    The other solution is to call the
    Report.Owner.FindComponents(aComponentName) to get access to the instance
    and then typecast it to the appropriate type and set the properties. The
    Report.Owner is the Form/DataModule upon which the component resides.

    In terms of what your code is trying to accomplish, when
    subreport.ParentPrintSetup is true (the default), then setting the main
    report's printersetup properties is all that is needed. If you set the main
    report's printersetup properties, then the subreport's will use those values
    as well. Only section subreports can have a different printersetup from the
    parent.


    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2011
    Hi Nard,

    Thanks for getting back to me. Sorry for the double post - I wasn't sure how
    "active" these news groups are, but obviously *very* ;-)

    The problem was all the event code directly access members which were freed
    by the Template.LoadFromFile.
    I could figure out the FindComponents method you suggested, but I managed to
    get it working with another workaround.
    I changed all the event code to use the "Sender: TObject" parameter and cast
    it to the type needed.
    It is not ideal since obviously old RTM files will not work with new events
    etc.
    But will have to suffice for now, since I cannot afford to upgrade to
    enterprise, nor have the time to invest in re-jigging the reports.

    Thanks again for your help.

    Rick.
This discussion has been closed.