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

How to modify RAP source code that is used in subreports

edited December 2009 in RAP
Hi,

In your Wiki is an example is given about how to modify RAP programs in
Code.
I have used this code, but it doesn't seem to work for code which is used to
calculate variables in sub-reports. I assume this information should be
found in lCodeModule.AllGlobalPrograms[liIndex].

However, in my example AllGlobalProgramCount = 4, but all code modules have
a nil value. It may have something to do with initialization, but I can't
find any documentation about this issue.

Thank you in advance,
Ruud Schneiders

Comments

  • edited December 2009
    Hi Ruud,

    For a subreport, you will want to initially get the code module of the child
    report rather than the main report.

    lCodeModule := raGetCodeModule(ppChildReport1);

    {event-handlers}
    for liIndex := 0 to lCodeModule.ProgramCount-1 do
    begin
    lProgram := lCodeModule.Programs[liIndex];

    lsSourceString := lProgram.Source;

    lsSourceString := StringReplace(lsSourceString, 'Hello', 'GoodBye',
    []);

    {do something here to modify the source and then re-assign it to the
    program}
    lProgram.Source := lsSourceString;


    end;

    --
    Regards,

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

    Best Regards,

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

    Thanks for your suggestion.
    If took me some time to find out how to obtain the Childreports, but it
    works.
    The final code is as follows:

    {Convert Subreports}
    ppReport1.GetSubReports(MySubReportsList);
    for MyIndex := 0 to MySubReportsList.Count-1 do Begin
    MyChildReport := MySubReportsList.Objects[MyIndex] as
    TppChildReport;
    lCodeModule := raGetCodeModule(MyChildReport);
    If Assigned(lCodeModule) then Begin
    {event-handlers}
    for liIndex := 0 to lCodeModule.ProgramCount-1 do Begin
    lProgram := lCodeModule.Programs[liIndex];
    lsSourceString := lProgram.Source;
    lsSourceString := MyTranslateRap(lsSourceString);
    lProgram.Source := lsSourceString;
    end;
    {global programs}
    for liIndex := 0 to lCodeModule.AllGlobalProgramCount-1 do Begin
    lProgram := lCodeModule.AllGlobalPrograms[liIndex];
    If (lProgram <> nil) then Begin
    lsSourceString := lProgram.Source;
    lsSourceString := MyTranslateRap(lsSourceString);
    lProgram.Source := lsSourceString;
    End;
    End;
    End;
    End;


    Kind regards,
    Ruud Schneidres

  • edited December 2009
    Hi Ruud,

    Excellent work.

    Another approach would be to create a report object loop and use the
    Subreport.Report property to retrieve the CodeModule.

    http://www.digital-metaphors.com/rbWiki/Delphi_Code/Layouts/Report_Object_Loop

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited December 2009
    Nico:

    You might want to update the Wiki example... many have asked, why do the
    fonts on subreports not get updated?

    Add the test for TppSubReport and recursively call AssifnFontToReport
    again...

    if lObject is TppSubReport then
    begin
    with lObject as TppSubReport do
    begin
    AssignFontToReport(aaFont, report);
    end;
    end;

    Walter

  • edited December 2009
    Thanks Walter,

    I just updated the article.

    --
    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.