Home General

How to determine whether a detailband has an odd or even number

edited April 2016 in General
Hello,

I have a subreport on the detail band of the main report. this subreport
has his own detail band. I would like to set the background color of the
subreport.detail via RAP depending on whether the
subreport.parentdetailband is the odd one or the even one.

Something like:

procedure DetailBeforeGenerate; (<-- of the subreport)
begin
if <odd_detail_of_the_main_report> then begin
Detail.Background1.Brush.Color := clWhite;
end
else begin
Detail.Background1.Brush.Color := clSilver;
end;
end;

Is there a way to determine from within a subreport, whether a
detailband of the main report (= parent of the subreport) has an odd or
even number?

Best regards,
Mark

Comments

  • edited April 2016
    Hi Mark,

    I assume you mean using RAP code. Here are two solutions that work in a
    simple test I tried. Note that for the detail you need to set Background1
    and Background2.


    From the childreport BeforeGenerate..

    var
    lParentReport: TppReport;
    begin
    lParentReport := TppReport(Report.ParentReport);

    if (lParentReport.Detail.Count mod 2) > 0 then
    Detail.Background1.Brush.Color := clWhite
    else
    Detail.Background1.Brush.Color := clSilver;

    Detail.Background2 := Detail.Background1;

    end;

    Or from the subreport.OnPrint

    var
    lChildReport: TppChildReport;
    begin

    lChildReport := TppChildReport(Subreport1.Report);

    if (Detail.Count mod 2) > 0 then
    lChildReport.Detail.Background1.Brush.Color := clWhite
    else
    lChildReport.Detail.Background1.Brush.Color := clSilver;

    lChildReport.Detail.Background2 := lChildReport.Detail.Background1;

    end;


    Best regards,

    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited April 2016
    Hi Nard,

    thank you. I used the second one, but had to modify it like this:

    var
    lParentReport: TppReport;
    lChildReport: TppChildReport;
    begin
    lParentReport := TppReport(Report.ParentReport);
    lChildReport := TppChildReport(Subreport1.Report);

    if (lParentReport.Detail.Count mod 2) > 0 then
    lChildReport.Detail.Background1.Brush.Color := clWhite
    else
    lChildReport.Detail.Background1.Brush.Color := clSilver;

    lChildReport.Detail.Background2 := lChildReport.Detail.Background1;

    end;

    because otherwise all details had the same color, because the
    childreport only has one detail all the time, I think.

    Best regards,
    Mark
This discussion has been closed.