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

Alternating Row Color?

edited April 2003 in General
Is there a way to know the current record number as a detail record prints?
Do you just use the DataPipeline? I would like to alternate the row color.

Thanks

--
Reid Roman
Future Generation Software
http://www.fgsoft.com

Comments

  • edited April 2003
    Hi Reid.

    There are a number of ways to accomplish this. I use a simple method using a
    boolean flag and a Shape object which is sent to the background. The detail
    text prints over the top of the shape. Declare a boolean flag somewhere where
    it is visible to the report and then toggle the flag value in the report's
    detail band BeforePrint event. I can change which of the first two lines the
    colour starts on by changing the value of the flag in the report's BeforePrint
    event. The overall effect is to print each row with an alternating background
    colour.

    procedure TReportForm.ppDetailBand1BeforePrint(Sender: TObject);
    begin
    // change the Shape colour based on the value of flag
    if ReportColourFlag then
    ReportForm.ppShape1.Brush.Color := clWhite
    else
    ReportForm.ppShape1.Brush.Color := clCream;
    // toggle the flag
    ReportColourFlag := not ReportColourFlag;
    // other processing here
    end;

    Good luck.

    Ron Hamer

  • edited April 2003
    Another thing to check is to reinitialize your boolean flag in the
    Report.OnStartPage event in case you always want to have the first band on
    each page start with the same color:)


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited April 2003
    Thank you everyone,

    I ended up using the BeforeGenerate() event to apply the MOD function
    against the RecNo property the underyling dataset to get the effect I
    needed.

    if (ppDBPipelineRuntime.Datasource.DataSet.Recno mod 2) = 0 then
    ppShapeOrderItem.Brush.Color := clWhite
    else
    ppShapeOrderItem.Brush.Color := ORDER_GRID_OFFSET_COLOR;

    Would be nice if the TppDetailBand had a Brush and Pen property.


    --
    Reid Roman
    Future Generation Software
    http://www.fgsoft.com
  • edited April 2003
    Actually after doing this I would like to change it to print the offset rows
    all the way down the page to the footer at the height of the detail band
    regardless of the row number of the dataset.

    Is this possible?


    --
    Reid Roman
    Future Generation Software
    http://www.fgsoft.com
  • edited April 2003
    Reid Roman wrote:

    DetailBeforePrint:

    if Detail.Count mod 2 = 0 then DBEdit1.font.color/ or shape1.brush.color
    := clsilver else ..... := clwhite;
  • edited April 2003
    Yes, this can be done. You'll need to create output draw commands, since the
    report engine will stop generating them because it is base don the dataset
    record count. Here is an example drawing lines down from the last detail to
    the bottom of the page. It is bottom aligned, but you can modify it to be
    aligned from the detail band position variable in the demo:

    http://www.digital-metaphors.com/tips/FillPageWithLines.zip

    An extended green bar demo would be cool. I'll try to put something together
    for exactly what you would like. In the meantime, give this demo a shot and
    try it out.


    Cheers,

    Jim Bennett
    Digital Metaphors

    ---------------------------------------
    Article: Draw Command Architecture
    ---------------------------------------

    Page Objects
    -------------

    When a report prints it generates Page objects. Each Page object contains an
    array of DrawCommand objects (Page.DrawCommands[]) that describe what needs
    to be rendered for the page.

    Report --> Pages.DrawCommands[] ---> Device (Printer, Screen, ..) --> final
    output


    DrawCommands Objects
    --------------------

    Component --> DrawCommand

    Each TppComponent generates a DrawCommand object each time
    it prints on a page. For example if the component is a TppLabel and prints
    at the top of the page - one draw command object will be created for each
    page. If the Label is in the detail band, many draw commands will be created
    for each page.

    A DrawCommand contains a complete description of the location and content to
    draw. See ppDrwCmd.pas for the existing DrawCommand class descendants
    (DrawText, DrawImage, etc.)

    Some of the basic DrawCommand classes such as DrawImage and DrawText, rely
    on the ScreenDevice and PrinterDevice classes to render their content. Other
    DrawCommand classes such as TppDrawBarCode and TppDrawRichText render
    themselves to the appropriate device canvas directly.


    Creating Custom Components
    --------------------------

    Each component has an associated DrawCommand class that is
    is the value of its DrawCommandClass property. For a Label,
    the DrawCommandClass is TppDrawText. This value is normally
    set in the constructor. Examples of the common components
    are located in ppCtrls.pas.



    constructor TmyComponent.Create(AOwner: TComponent);
    begin

    inherited Create(AOwner);

    DrawCommandClass := TppDrawText;

    end;


    Each time the component prints, a DrawCommand object of
    the designated DrawCommand class will automatically be
    created and the components PropertiesToDrawCommand method
    will be called. You override this method to transfer the
    appropriate property values from the component to
    the drawcommand object.


    {------------------------------------------------------------------------}
    { TmyComponent.PropertiesToDrawCommand }

    procedure TmyComponent.PropertiesToDrawCommand(aDrawCommand:
    TppDrawCommand);
    var
    lWrappedText: TStrings;
    lTextBuf: PChar;
    lPrinter: TObject;
    lDrawText: TppDrawText;
    llCharPos: Longint;
    begin

    inherited PropertiesToDrawCommand(aDrawCommand);

    if not(aDrawCommand is TppDrawText) then Exit;

    lDrawText := TppDrawText(aDrawCommand);

    {set properties here}

    lDrawText.Alignment := Alignment;
    lDrawText.AutoSize := AutoSize;
    lDrawText.Color := Color;
    lDrawText.Left := PrintPosRect.Left;
    lDrawText.Top := PrintPosRect.Top;
    lDrawText.Height := PrintPosRect.Bottom - PrintPosRect.Top;
    lDrawText.Width := PrintPosRect.Right - PrintPosRect.Left;
    lDrawText.Text := Text;
    lDrawText.Transparent := Transparent;
    lDrawText.WordWrap := WordWrap;
    lDrawText.Font := Font;


    end;



    Creating Custom DrawCommands
    ----------------------------

    When you create a descendant component you can either
    use an existing draw command class or create a new one.
    For the TeeChart wrapper components, we chose to use
    the existing DrawImage class to specify the TeeChart
    as a metafile image. So it is not always necessary to
    create a draw command class.

    Examples of DrawCommand classes are located in ppDrwCmd.pas.
    A drawcommand will contain published properties that
    contain a complete description of the location and
    content to be rendered.

    DrawCommand classes must be registered - see the
    initization and finalization sections at the bottom
    of the ppDrwCmd.pas unit for an example.

    DrawCommand classes should publish all properties
    used to describe the object.

    DrawCommand classes must implment the Assign
    method to assign the values of all published
    properties from one draw command to another.


    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com


  • edited April 2003
    Check this out:

    http://www.digital-metaphors.com/tips/GreenBar.zip


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited April 2003
    Thank You!


    --
    Reid Roman
    Future Generation Software
    http://www.fgsoft.com
This discussion has been closed.