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

Accessing subreport programmatically

edited June 2005 in Subreports
Hello,

Can I access a report's subreports programmatically? I'd like to set the
datapipline of a subreport, but I can't seem to get ahold of it
programmatically. Here's the background: The report works if I use the
runtime designer and click on the subreport tab (at the bottom), then click
Report - Data. All I have to do is click "ok" and the report works (meaning
that I don't have to modify the master and detail piplines - they seem to
already be setup). If I don't do that then the subreport will simply show
the same record an infinte number of times and I get the elusive neverending
"calculating page n..." problem. Thanks.

Corey O'Mara
comara@promed-services.com

Comments

  • edited June 2005

    You can access any elements in the report using the Report.Bands[].Objects[]
    structure. If you encounter a TppSubreport in the Objects[] array, then you
    can typecast it and it traverse its elements as well. The Subreport.Report
    property provides access to the ChildReport. You can set
    Subreport.Report.DataPipeline or for convenience you can also set
    Subreport.DataPipeline (it is a pass thru).

    The Report.GetSubReports method is show below. You can use this to a get a
    list of all subreports. Here is the code to that method (ppClass.pas). It is
    a good example of how to traverse the report elements.


    {TppCustomReport.GetSubReports

    Returns a list of handles to all of the TppChildReport objects within a
    report
    in the Objects property of the TStrings. The Caption of the TppSubReport
    component is saved in the main property of the TString.}

    procedure TppCustomReport.GetSubReports(aReportList: TStrings);
    var
    liBands: Integer;
    liBand: Integer;
    lBand: TppBand;
    liObjects: Integer;
    liObject: Integer;
    lObject: TppComponent;
    begin

    liBands := BandCount;

    for liBand := 0 to liBands - 1 do
    begin

    lBand := Bands[liBand];

    liObjects := lBand.ObjectCount;

    for liObject := 0 to liObjects - 1 do
    begin

    lObject := lBand.Objects[liObject];

    if (lObject is TppSubReport) and (TppSubReport(lObject).Report <>
    nil) then
    begin
    aReportList.AddObject(lObject.Caption,
    TppSubReport(lObject).Report);

    TppSubReport(lObject).Report.GetSubReports(aReportList);
    end;

    end; {for, each component}

    end; {for, each band}

    end; {procedure, GetSubReports}



    --
    Nard Moseley
    Digital Metaphors Corporation
    http://www.digital-metaphors.com


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited June 2005
    Also, if you want to get only the subreports for the current report level,
    use TppReport.GetFirstLevelSubReports. I use this routine recursively to set
    my Pipelines at run-time.

    David


This discussion has been closed.