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

Choosing a Group programmatically at run time

edited March 2005 in General
Hi there,

I've got a report that we sort on a couple of different indexes depending on
what the users need to see.
I'd like to be able to setup several group footers to give a different set
of break totals depending on the index chosen. I have created several
appropriate Groups but can't figure out how to get them to selectively print
when required.

Is it possible to do this programmatically before calling report.print. Or
any way that will work for that matter?

Thanks in advance.
Regards,
Bruce Rogers.

Comments

  • edited March 2005
    Hi Bruce,

    It is possible to control which groups are used in your report using the
    TppReport.AddGroup and TppReport.RemoveGroup routines. Documentation on
    these methods can be found in the RBuilder.hlp file.

    --
    Regards,

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

    Best Regards,

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

    That looks like it does the trick.

    Regards,
    Bruce.

  • edited March 2005
    Hi Nico,

    I spoke too soon, I'm getting odd results here's what I'm trying.

    The only band in each group that has anything in it is the footer, that's
    where I want the sub total stuff.

    ppReport1.RemoveGroup(ppGroup1);
    ppReport1.RemoveGroup(ppGroup2);
    ppReport1.Print;

    This stops the breaks firing during the report but both footer bands print
    at the end of the report.

    To conditionally switch them on I tried,

    ppReport1.RemoveGroup(ppGroup1);
    ppReport1.RemoveGroup(ppGroup2);
    if IndexA then
    begin
    set index to A;
    ppReport1.AddGroup(ppGroup1);
    end else
    if IndexB then
    begin
    set Index to B;
    ppReport1.AddGroup(ppGroup2);
    end;

    This gave inconsistent results the breaks fired a lot more that they should
    have.
    If you leave the fiddle with group code out the reports print perfectly,
    swaps sort order etc. The both breaks print in the correct positions etc.

    What am I missing here?

    Thanks and regards,
    Bruce.


  • edited March 2005
    Hi Bruce,

    Sorry, my previous advise was incorrect. Instead of creating the groups at
    design time and adding and removing them, try creating the groups at run
    time based on the condition you show below. See the article below for
    information on how to dynamically create a group. This way when you remove
    a group, you can completely free the TppGroup object removing any chance of
    the report breaking on the old group.

    ----------------------------------------------------
    Tech Tip: Creating a Group in Code
    ----------------------------------------------------


    How can I dynamically create a report group at run-time?


    example code:
    -------------

    uses
    ppClass, ppGroup, ppClasUt;


    function AddGroupToReport(aBreakName: String; aDataPipeline:
    TppDataPipeline; aReport: TppCustomReport);
    var
    lGroup: TppGroup;
    lGroupBand: TppGroupBand;

    begin


    {add group to report}
    lGroup := TppGroup(ppComponentCreate(aReport, TppGroup));

    lGroup.Report := aReport;

    lGroup.BreakName := aBreakName;
    lGroup.DataPipeline := aDataPipeline;

    {add group header and footer bands }
    lGroupBand := TppGroupBand(ppComponentCreate(aReport,
    TppGroupHeaderBand));
    lGroupBand.Group := lGroup;

    lGroupBand := TppGroupBand(ppComponentCreate(aReport,
    TppGroupFooterBand));
    lGroupBand.Group := lGroup;


    end; {procedure, AddGroupToReport}

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