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

Some troubles with Auto-Creatation TppLabel

edited July 2003 in General
I want create some TppLabel objects automatically in the detailband's before
event handle. But the Tpplabel are always not display in the report although
the Tpplabel object's band property is given with the detailband.

Comments

  • edited July 2003
    I'm sorry that I have taken a mistake. The following is the right meanings:

    I want create some TppLabel objects in the detailband's beforeprint
    event handle. But the Tpplabel are always not display in the report although
    the Tpplabel object's band property is given with the detailband.
    How can I carry out it?
  • edited July 2004
    Hello,

    The DetailBand.BeforePrint event fires too late to begin adding label
    components to the report. You will need to add them before calling
    Report.Print, or you can add TppDrawText drawcommands manually to a position
    on each page.

    ---------------------------------------
    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.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited July 2004
    Thank you.

    I want to create some Tpplabel objects dynamically in the detailband of a
    report, and assign a field value of all records of a dataset to each of
    them. Can you tell more about it to complete it?


  • edited July 2004
    Hello,

    Try creating a TppDBText rather than a TppLabel component. Unfortunately if
    you would like to create these objects dynamically, you will need to create
    them and add them to the report before you call Report.Print. Otherwise you
    will need to create TppDrawText drawcommand objects and place them on the
    page in the correct position, and assign their values manually to the field
    value in your dataset. Something like the following...

    procedure TForm1.ppDetailBand1BeforePrint(Sender: TObject);
    var
    lDrawText: TppDrawText;
    begin

    lDrawText := TppDrawText.Create(nil);
    lDrawText.Page := ppReport1.Engine.Page;
    lDrawText.Top := ppReport1.DetailBand.PrintPosRect.Bottom;;
    lDrawText.Left := ppReport1.PrinterSetup.PageDef.mmMarginLeft;
    lDrawText.Width := //Text Width
    lDrawText.Height := //Text Height

    lDrawText.Text := ppReport1.DataPipeline['MyField'];;

    end;

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited July 2004
    Thanks. I'll try this method soon after, and I should reply the result to
    you.


  • edited July 2004
    I'm just a beginner in using ReportBuilder, and I am very glad of
    getting your help. I have tested your method, however, it seems not work
    well. I
    hope the string 'abcd' display at the bottom of ppDbText1 and the left of
    ppDbCalc1 in every detailband, but it always display at the top left corner
    of the report. My code is in accessories. I am working in Delphi5 and
    RBuilder Enterprise Edition 7.03.


  • edited July 2004
    Hi,

    Remember that when you are creating DrawCommands, you are assigning the top
    and left position on the current page, not the band. You will need to
    manually position these drawcommands in the space where the detail band
    should be to see the effect you are after. Again, this would be much
    simpler if you created a single TppDrawText component before you call
    Report.Print because all this will be done automatically for you.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.