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

changing the font in the detail band at runtime.

edited December 2003 in General
I am trying to alter the font in the detail band in runtime for based upon a
criteria in my core query. I test the status of a visit and call a
procedure as in below. The problem I am having is when the last item on the
page is cancelled, the Tital and Header pick up the same font (strike-out)
until the next record that does not meet that criteria.

I don't understand how this test is "jumping" out of it's band?
Larry


procedure TForm_StudyReport.ppReport1DetailBand1BeforePrint(
Sender: TObject);
Var
...
Begin
...

if Query1VISIT_STATUS.AsString[1] = 'X' then
VistStatus(True)
else
VistStatus(False);
...
End;

procedure TForm_StudyReport.VistStatus(Cancelled:Boolean);
var
I:integer;
fsCancel : TFontStyles;
DetailLabel : TppLabel;
begin
fsCancel := [fsStrikeOut];
for i := 0 to ComponentCount - 1 do
Begin
if Components[i] is TppLabel then
begin
DetailLabel := Components[i] as TppLabel;
If Cancelled then
DetailLabel.Font.Style := DetailLabel.Font.Style + fsCancel
Else
DetailLabel.Font.Style := DetailLabel.Font.Style - fsCancel;
end;
end;
end;

Comments

  • edited December 2003
    You are looping through all of the components on all of the bands and
    changing ALL Labels. You need to just loop through the report objects
    looking for labels that are on the detail band. Here's an example how:

    procedure VisitStatus (Cancelled:Boolean);
    var
    iBandNo : Integer;
    iObjectNo : Integer;
    begin
    for iBandNo := 0 to Report.BandCount - 1 do
    begin
    if (Report.Bands[iBandNo] is TppDetailBand) then
    begin
    for iObjectNo := 0 to Report.Bands[iBandNo].ObjectCount - 1 do
    begin
    if Report.Bands[iBandNo].Objects[iObjectNo] is TppLabel then
    begin
    with (Report.Bands[iBandNo].Objects[iObjectNo] as TppLabel) do
    begin
    if Cancelled then
    Font.Style := Font.Sytle + fsCancel
    else
    Font.Style := Font.Sytle - fsCancel;
    end;
    end;
    end;
    end;
    end;
    end;

    HTH,
    Chuck Van Acker
    Alogent Corp.
  • edited December 2003

    A reader replied in person and typed me off to my error. It seems that I
    was not adequately containing my rule to just the Detail band. I am posted
    the fix in case anyone else is interested in how it is done correctly.
    Thanks to the sender and all.
    Larry Killen

    ps I was assuming that the Report1DetailBand1BeforePrint event handler is
    called after, and if anything, it would cause trouble in the footer or
    summary. I guess I don't understand the order of events here.


    procedure TForm_StudyReport.VistStatus(Cancelled:Boolean);
    var
    iBandNo : Integer;
    iObjectNo : Integer;
    fsCancel : TFontStyles;
    begin
    fsCancel := [fsStrikeOut];
    for iBandNo := 0 to ppReport.BandCount - 1 do
    begin
    if (ppReport.Bands[iBandNo] is TppDetailBand) then
    begin
    for iObjectNo := 0 to ppReport.Bands[iBandNo].ObjectCount - 1 do
    begin
    if ppReport.Bands[iBandNo].Objects[iObjectNo] is TppLabel then
    begin
    with (ppReport.Bands[iBandNo].Objects[iObjectNo] as TppLabel) do
    begin
    if Cancelled then
    Font.Style := Font.Style + fsCancel
    else
    Font.Style := Font.Style - fsCancel;
    end;
    end;
    end;
    end;
    end;
    end;




This discussion has been closed.