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

Band lines and brush

edited February 2003 in General
Hello,

I wish to print a bottom line for each detail band without using a TppShape.
I also wish to paint a background color at every to detail bands. These two
features are selectable by the end users.

What do you sugest me to do ? Inherit from TppDetailBand ? Can I register a
new band class with the report designer ?

Thanks,

--
Fabio Lindner

Comments

  • edited February 2003
    You can create draw commands if you don't want to create components in the
    report layout.

    The easiest way to get alternate colors in a band is to toggle a TppShape's
    color or visibility. You can also use the RBAddOn component set which has a
    feature to do this. Surf www.bancoems.com\RBAddOn.htm

    Here are some draw command examples which are related to what you are
    asking:

    {alternate detail band color}
    http://www.digital-metaphors.com/tips/GreenBarDrawCommand.zip

    {adds the line at the bottom of a group of detail bands per page}
    http://www.digital-metaphors.com/tips/BorderAroundGroupProj.zip


    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 February 2003
    Thanks.

    Maybe I can descend from TppReport and implement these features build-in.

    --
    Fabio Lindner
  • edited February 2003
    We don't recommend creating report descendents from a maintenance
    standpoint, but it may be possible to do this. Off the top of my head, in
    the Create override, start with adding ciEngineEndPage to the EventNotifies
    inherited set.

    EventNotifes := EventNotifies + [ciEngineEndPage];

    Then in the EventNotify override routine, you can check to see if the engine
    has finished the page by checking the aEventID parameter. Then add you draw
    commands in that timing to the Engine.Page property as shown in the demos.
    You could add new properties to the report and then modify the designer
    MergeMenu property to add a menu item to check or a dialog to allow the end
    user to control this feature.

    The other part is tracking where to add a draw command. One way to approach
    it is to create a class registry where you can register a draw command
    generator class to a report template or report description. This way you can
    let the user more easily choose how to alter the report layout, without
    hardcoding the features into the report descendent. You will have to setup
    the commnication (via TppCommunicator in ppComm.pas) in order to track the
    position of the detail band or group footer band, parallel to what the demos
    show how to do using Delphi event handlers.

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    Thanks, I'll try something like that.

    --
    Fabio Lindner

    EventNotifies
    engine
    draw
    end
    approach
    can
    demos
This discussion has been closed.