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

How to Print Report or generate Custom File output

edited June 2003 in General
I have a report that can go to the printer or to an output file. If it goes
to the output file I only need to output the ppDBxxx
components,no pplabels or lines etc. How can I scan the report and output
only the data?
Thanks

Comments

  • edited June 2003
    James,

    You can "scan" the report for certain components using a Report Object Loop.
    Then you will need to check if each component is DataAware by using the
    TppComponent.IsDataAware routine.

    ----------------------------------------------
    Tech Tip: Loop Thru All Objects in a Report
    ---------------------------------------------

    A ReportBuilder report is composed of a set
    of components. The basic structure is

    Reports.Bands[].Objects[]

    The bands and objects within the report can
    be accessed directly by object name or
    via the Bands and Objects array properties.

    uses
    ppClass;


    procedure AssignFontToReport(aFont: TFont; aReport: TppCustomReport);
    var
    liBand: Integer;
    liObject: Integer;
    lObject: TppComponent;

    begin

    for liBand := 0 to aReport.BandCount-1 do

    for liObject := 0 to aReport.Bands[liBand].ObjectCount-1 do
    begin
    lObject := aReport.Bands[liBand].Objects[liObject];

    if not(lObject.IsDataAware) then
    lObject.Visible := False;

    end;

    end;


    --
    Best Regards,

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

    this is great but seems to skip the subreports
  • edited June 2003
    Here is a code example to get the main report and all subreports:

    procedure ReportObjectLoop;
    var
    slSubReports : TStringList;
    iSubReportCount : Integer;
    begin

    AnalyzeReportObjects(ppReport1);

    //Now handle the subreports, if any.
    slSubReports := TStringList.Create;
    //Get a list of all the Sub Reports
    ppReport1.GetSubReports(slSubReports);
    if slSubReports.Count > 0 then
    for iSubReportCount := 0 to slSubReports.Count - 1 do
    begin
    AnalyzeReportObjects((slSubReports.Objects[iSubReportCount]) as
    TppCustomReport);
    end;
    FreeAndNil(slSubReports);
    end;

    procedure AnalyzeReportObjects ( oReport : TppCustomReport );
    var
    iBandIdx : Integer;
    iObjIdx : Integer;
    begin
    with oReport do
    begin
    for iBandIdx := 0 to BandCount -1 do
    for iObjIdx := 0 to Bands[iBandIdx].ObjectCount - 1 do
    begin

    code....

    end;
    end;
    end;


    Regards,
    Chuck Van Acker
  • edited June 2003
    Hi Chuck!

    Also, you can use a recursive version of the report object loop when you
    find a TppSubreport to pass the TppSubreport.Report object to the
    AssignFontToReport example method in the article.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.