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

runtime creation of subreports

edited March 2005 in Subreports
Hello,

Can someone help me out

I want to create subreports at runtime based on user selected data in a grid
with treeview grouping.

griddata

accountno
[+] 123456 sum: 567,89
[-] abcdef
date amount
01-01-05 5000,-
01-03-05 7000,-

The data is posted in ClientDataSets from the grid
based on posting I create something like this
where aReport is my mainreport

myChild := TppChildReport.Create(Self);
mySubReport := TppSubReport.Create(Self);
mySubReport.Band := aReport.DetailBand;
mySubReport.SetReportProperty(myChild);
mySubReport.PrintBehavior := pbSection;
mySubReport.ResetPageNo := False;

Is this the right creation and assignment of the sub/child to the detailband
of my report?

Thanks for your help,

Bert Blok

Comments

  • edited March 2005
    Hi Bert,

    Take a look at the following article on creating subreports in code.

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

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