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

How to access a specific component in a report stored in a database?

edited January 2006 in End User
Hello all.
I'm using rbuilder 9.03 and delphi 7.
I want to be able to: after loading a report stored on a database , access a
specific component in the report (in run-time), or in the subreport of the
report. How can I do this? How can I 'navigate' through the components of
the loaded report? I tried with the component list but didn't work.
Any tips on this?
Thanks in advance.
Best Regards

Goncalo Martins

Comments

  • edited January 2006
    Hi Goncalo,

    If you would like to navigate through subreports as well, you will need to
    make a recursive call to the looping function when a subreport objects is
    encountered.

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

    Below is an example of using the Bands and
    Objects array properties to change the font for
    all objects on a report.


    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 lObject.HasFont then
    lObject.Font := aFont;

    end;

    end;


    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2006
    Hello.
    This is working fine on the report, but I'm having trouble navigating in the
    sub-report.
    If I use the band in the subreport, it continues accessing the main report.
    How can I navigate in the sub-report objects?
    Thanks

    Goncalo

  • edited January 2006
    > If you would like to navigate through subreports as well, you will need to

    :)

    Here is the altered example...

    uses
    ppSubRpt;

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

    //recursive call
    if (lObject is TppSubreport) then
    AssignFontToReport(aFont, TppSubreport(lObject).Report);

    if lObject.HasFont then
    lObject.Font := aFont;

    end;
    end;

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2006
    :-) Ok, thanks.
    I was having problem with this kind of encoding:
    TppSubreport(lObject).Report
    Now is working great.
    Thanks

    Goncalo

This discussion has been closed.