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

GlobalOnCreate not called when printer changes in preview

edited February 2007 in General
I suppose there is a major bug in the event handling of
reportbuilder version 10.05. I observed following
behaviour:

1) When you load a report from a template in Delphi 6 with RB7.04
the RAP-Event GlobalOnCreate is fired

2) show the report in Preview-Mode

3) press the print button in the preview window

4) the print dialog appears.
Now change the printer (IMPORTANT) and press ok

5) at that time the rap-event
GlobalOnDestroy is called for the previewing report

6) Now for the printing report the RAP-event
GlobalOnCreate is fired again

7) the report prints

8) at the end the RAP-event GlobalOnDestroy fires


When you execute the same actions within Delphi2006 and
and ReportBuilder10.05 then Step 6 is MISSING.

For the printing report GlobalOnCreate is never called and all logic
you have coded in this event is not executed.

I believe the reason why is located in the method
TppEngine.Init (ppEnginge.pas)

In RB7.04 the method contains following code


procedure TppEngine.Init;
begin
....
{must fire before opening pipes - 5.01}
if not(PrintingSubReport) and not(FMainReportStarted) then
Report.TriggerCodeModuleCreate;


In RB10.5 the method code has changed to


procedure TppEngine.Init;
begin
....
{must fire before opening pipes - 5.01}

if not(PrintingSubReport) and not(FMainReportStarted) then
begin
SendEventNotify(Self, ciReportBeforeOpenDataPipelines, nil);
Report.TriggerCodeModuleBeforePrint;
end;


The method TriggerCodeModuleCreate will only be called
once in TppReport.InitializeParameters and that is not enough!


function TppReport.InitializeParameters: Boolean;
var
lbCancel: Boolean;
lParams: TraParamList;
begin

TriggerCodeModuleCreate; // fire RAP global OnCreate



When the main report contains subreports the problem becomes
evident for every single subreport.
GlobalOnCreate for the subreports is never called,
when you print from the preview window and changed the printer.

To reproduce the bug you can use the rap-demo application with report
rap001.rtm and code some trace statementes into the GlobalOnCreate and
GlobalOnDestroy event handlers.


Thanks for a quick fix in advance.

Frank Neuhaus
CPA SoftwareConsult GmbH
www.cpa.de

Comments

  • edited February 2007
    Hi Frank,

    The change to how the GlobalOnCreate event in RAP behaves was made on
    purpose due to the overwhelming feedback from our users that this event was
    firing too often. The GlobalOnCreate event is now designed to fire only
    once for each report as the code module is created. For RB 7.04, this event
    behaved much like the BeforePrint event. For your situation, try moving
    your code to the BeforePrint event if you would like the code to be executed
    every time the report is printed.

    --
    Regards,

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

    Best Regards,

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

    the point and the problem is that you call GlobalOnDestroy (Step 5)
    before the print actually starts.

    Imagine following example:

    - the report is loaded and in the GlobalOnCreate event a variable
    XYZ of type TStringList is created.

    - the preview works as expected

    - know the user presses the print button and changes the printer

    - GlobalOnDestroy is called and the variable XYZ is freed (Step 5)

    - now the print process begins without a new call to GlobalOnCreate

    - the report is then generating without a valid variable reference
    for XYZ and will produce junk.
    This is exactly what happens to some of our reports

    When you change the logic in the way that GlobalOnCreate is only called
    once, the same must be true for GlobalOnDestroy. The GlobalOnDestroy
    should only be called at the end when the TppReport object is destroyed.

    Regards
    Frank
  • edited February 2007
    Hi Frank,

    Thanks for the info. There is now a patch available that solves this issue.
    Please send a small email to support@digital-metaphors.com requesting the
    patch and we'll send it to you as soon as possible.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.