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

Multiple independent datasets

edited June 2005 in Subreports
I've been trying to avoid using master-detail relationship. I've
tentatively put what would have been child-table records into separate files
for portability, where the number of such files varies. Is it possible to
include each of those files in report-subreports where after the first file
is traversed the next file is assigned to the pipeline, traversed, and on
through the last file? From your developer's guide page 41, a known number
of independent datasets (no master or linkage) can be placed each in its own
subreport as 'chapters' at design time. When the number of datasets and
subreports is unknown at design time it sounds like I would need to instead
create the report and subreports in code, I suppose loading the subreports
and assigning datasets once the number of such has been determined at run
time? Not something that can be done at design time?

Thanks in advance.

Charles Wood

Comments

  • edited June 2005
    Hi Charles,

    ReportBuilder does not contain a feature that will dynamically create
    subreports depending on how many dataset you have, this must be done at run
    time. It should not be that difficult however. Take a look at the
    following article on creating subreports in code, then you may want to take
    a look inside the TechTips newsgroups under the Code Based topic for more
    useful articles on creating report object in code. Let me know if you have
    any questions along the way.

    -------------------------------------------------
    TECH TIP: Creating a SubReport in Code
    -------------------------------------------------

    A subreport is comprised of two objects:

    1. SubReport control
    The subreport control is added to a band of the
    'parent' report. It has properties such as
    ShiftRelativeTo, PrintBehavior, etc.
    In the Report Designer, the subreport is drawn
    as a rectangle.


    2. ChildReport
    The child report is a descendant of CustomReport and has
    most of the same properties as a standard Report.
    The child report has a separate layout workspace in the report
    designer that is accessible by selecting the tabs at the bottom
    of the designer.




    When dynamically creating a subreport in code you need to create the
    subreport and the underlying child report. The subreport.Report property can
    then be used to access the child report.

    This is demonstrated in the following example:




    var
    lSubReport: TppSubReport;
    lReport: TppChildReport;
    lLabel: TppLabel;
    lDBText: TppDBText;


    begin

    lSubReport := TppSubReport.Create(Self);

    {add to the main report's detail band}
    lSubReport.Band := ppReport1.DetailBand;

    {create the child report (parameters: main report) }
    lSubReport.CreateReport(ppReport1);

    lReport := TppChildReport(lSubReport.Report);

    {assign a datapipeline}
    lReport.DataPipeline := plCustomers;

    {create the default set of bands}
    lReport.CreateDefaultBands;

    lLabel := TppLabel.Create(Self);
    lLabel.Band := lReport.TitleBand;
    lLabel.Caption := 'Customers';

    lLabel.Font.Name := 'Times New Roman';
    lLabel.Font.Size := 24;

    lDBText := TppDBText.Create(Self);
    lDBText.Band := lReport.DetailBand;
    lDBText.DataPipeline := plCustomers;
    lDBText.DataField := 'CustNo';

    lDBText.Color := clYellow;
    lDBText.Font.Name := 'Times New Roman';
    lDBText.Font.Size := 12;



    end;


    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2005
    Thanks for your quick reply. I see I can add a varying number of pbSection
    subreports in code, with dbCalc in the summary band. I like it. Adding a
    dbCalc to the parent report yeilds zero as the grand total, and I wonder if
    I am supposed to be using a variable component there instead as an
    accumulator? I assume the dbCalc default type is SUM?

    Thanks again.

    Charles


  • edited June 2005
    Hi Charles,

    Yes, when making calculations across subreports into the main report, you
    will need to use variables instead of DBCalc components. All you need to do
    is place a TppVariable inside the detail band of the subreport and inside
    its OnCalc event, update the value property of any other variables in your
    report (i.e. in the summary band of the main report).

    --
    Regards,

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

    Best Regards,

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

    Before proceeding in code, in the designer I am playing with a report that
    contains two pbsection subreports. I can't get the report's summary band
    tppvariable to update in other than dtString, and the component doesn't seem
    to get its value property at the right time.

    I put a TppVariable inside the detail band of the second subreport. And I
    put a TppVariable in the summary band of the report and use the OnCalc event
    of the second subreport TppVariable to update the value of the summary band
    report TppVariable. Note these are currency fields in the table itself.

    The report's summary band variable is only non-zero when its data type is
    dtSring. That is the case regardless if I use the fields asstring property
    in the subreport variables calc event, or just take the subreport
    summarybands dbcalc.value, which is a currency field in the table and dbcalc
    component. dtCurrency for the report summary band variable always gives a
    zero result.

    And the report summary band tppvariable's value isn't produced at all if in
    the report previewer at run time I use the last page arrow to display the
    summary page. The value seems to only be calculated if I step through the
    report one page at a time to get to the summary page of the report.

    I can't quite see what I am doing wrong and would appreciate any
    suggestions. Eventually I'ld like both subreport1 and subreport2's
    tppVariable components to update the report summary band tppvariable to
    produce a grand total for both subreports.

    Charles


  • edited June 2005
    Hi Charles,

    Sorry, I'm having trouble visualizing what is happening that could be
    causing this behavior. If possible, please send a small example of this
    issue to support@digital-metaphors.com in .zip format and I'll take a look
    at it for you.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2005
    I got it working and wanted to thank you again for your help.

    Charles

This discussion has been closed.