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

Obtaining attributes of report objects

edited April 2002 in General
I would like to be able to loop through the objects contained in a report
layout to determine:
a. If the object is a DBText field.
b. Assuming a is True (object is DBText), what is the datatype?
c. If a is true, and b is in a range of allowable datatypes, apply a
specific field format.

I need to do this to update about 20 EUR reports that do not have formats
specified (typically on dtSingle datatypes). My other option is to do them
all manually, and since this would involve about 100 fields per report (and
applying formats is not a multi-select function),I'd rather automate the
process. I would like to temporarily add this process to my LoadEndEvent,
and remove it after I've auto-formatted all of the necessary reports.

I know how to get the loop down to the Report.Bands[i].Components[i] level,
but I can't see any properties or methods that appear to access what I need
at this point.

I am using RB Ent 5.56 in a Delphi 4 application.

Thanks in advance.

Comments

  • edited April 2002
    You need to use the the 'is' operator to check whether the component is a
    TppDBText. Once one is found the datapipeline can be queried to check the
    datapipe. Lastly, the RB components have a DisplayFormat property that can
    be set. For example...

    procedure ApplyFormatToReport(aReport: TppReport)
    var
    i, j: Integer;
    lComponent: TComponent;
    lDBText: TppDBText;
    begin

    for i := 0 to aReport.BandCount - 1 do
    for j := 0 to aReport.Bands[i].ObjectCount - 1 do
    begin
    lComponent := ppReport1.Bands[i].Objects[j];
    if (lComponent is TppDBText) then
    begin

    lDBText := TppDBText(Component);

    case lDBText.DataPipeline.GetFieldDataType(lDBText.DataField) of
    dtString,
    ...
    dtDouble: lDBText.DisplayFormat := aDisplayFormat; // insert
    your format string here
    else: lDBText.DisplayFormat := aDefaultDisplayFormat;
    end;

    end

    else if (lComponent is TppSubreport) then
    ApplyDisplayFormatToReport(TppSubreport(Component).Report);

    end;
    end;

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

This discussion has been closed.