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

Stretching tPPShape when another object Stretches

edited April 2009 in General
Hi,

I'm writing a report that has a shaddown in it's design.

On the report I have a tppDBMemo component set, and underneath it I have a
tPPShape component set at the same height and width, but offset by 8x8
pixels to the bottom left to give a shaddow feel.

(The tppdbmemo component has transparent set to false)

This works fine unless the text populating the memo field forces the memo to
stretch, in which case the memo (and corresponding band) will stretch to the
required length.

However, when this happens the underlying shape component does not stretch.
I turned on the 'strecthwithparent' property, which causes it to stretch,
but it only stretches to the end of the memo component (thus while the tops
are offset by 8 units, the bottoms are level).

I tried setting the report to TwoPass, and putting a ppshape.height :=
ppdbmemo.height code in the onprint event of the ppshape control, but this
doesn't appear to have helped.

Can you please advise how I should go about this?

Thanks & Regards

Adam.

Comments

  • edited April 2009
    Hi Adam,

    Depending on the type of shape you are using, you could possible place your
    memo inside a region component set to stretch and anchor the memo to the
    bottom, keeping the spacing correct. A region is essentially a stretching
    rectangle when printed to paper or the screen.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2009
    Good Morning Nico,

    Thanks for your reply. Unfortunately I can't seem to be able to set the memo
    to anchor to both the top and the bottom (or can I the shape).

    I have placed a small demo / example of what I am trying to achieve at:

    http://www.wsdsites.net/temp/rbuldershadexample.zip

    The first button prints out the form roughly how I want it to look. (With a
    'shaddow').

    The second button prints out the form when more text is added to the memo
    component.

    In the example I have used a tppMemo component, but in my real application I
    am using a tppDBMemo (as the data comes from a database), but I don't think
    it should make much difference.

    What I need the background shape to do is to stay the same height as the
    ppmemo component, but also keep it's offset (so it appears like a shaddow).

    Thanks & Regards

    Adam.



  • edited April 2009
    Hi Adam,

    Thanks for the example. You are correct in that regions are not a good
    solution for this case.

    Try using the OnDrawCommandCreate event of the shape to calculate the height
    of the memo and adjust its size accordingly. In my testing the following
    code below gave good results.

    uses
    ppDrwCmd, ppUtils, ppTypes;

    ...

    procedure TForm1.ppShape1DrawCommandCreate(Sender, aDrawCommand: TObject);
    begin
    TppDrawShape(aDrawCommand).Height := CalcMemoHeight(ppMemo1);

    end;

    function TForm1.CalcMemoHeight(aMemo: TppMemo): Integer;
    var
    lCanvas: TCanvas;
    liTextHeight: Integer;
    liMemoHeight: Integer;
    liIndex: Integer;
    begin

    lCanvas := ppReport1.Printer.Canvas;
    lCanvas.Font := aMemo.Font;
    liTextHeight := lCanvas.TextHeight('W');

    liMemoHeight := 0;

    for liIndex := 0 to aMemo.Lines.Count - 1 do
    liMemoHeight := liMemoHeight + liTextHeight;

    Result := ppToMMThousandths(liMemoHeight, utPrinterPixels, pprtVertical,
    ppReport1.Printer);

    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2009
    Good Morning Nico,

    Thanks for your reply. I was able to get your suggestion to work with the
    sample project, but am having problems with my real project.

    In order for it to work in my real project I needed to change the TppMemo
    refference to a TppDBMemo reference.

    When the following line runs:



  • edited April 2009
    Sorry - hit the wrong key and it sent too early...

    _______

    Good Morning Nico,

    Thanks for your reply. I was able to get your suggestion to work with the
    sample project, but am having problems with my real project.

    In order for it to work in my real project I needed to change the TppMemo
    refference to a TppDBMemo reference.

    When the following line runs:


    it counts my DBMemo.Lines.Count as having 2 lines.

    The data that I have in my table has 16 lines worth. There are only 2
    carriage returns in the field, and the rest is word-wrapped, but it would
    appear that the lines.count only calculate on the carriage returns, and
    doesn't take into account the word-wrapping.

    Could you suggest please what I need to do to get this to work with a
    TppDBMemo component with wrapping text?

    Thanks & Regards

    Adam.
  • edited April 2009
    Hi Nico,

    In addition to this, I have been able to replicate my problem using just a
    TppMemo component. I have uploaded a demo of the issue to:

    http://www.wsdsites.net/temp/rbuldershadexample.zip

    Thanks for all your help!

    Adam.
  • edited April 2009
    Hi Adam,

    Ok, this case is a bit different. For a DBMemo, the lines are not retrieved
    from the DB until after the shape is created. The same concept applies for
    your example where you are only adding a single line and letting
    ReportBuilder wrap the text.

    In these cases you will need to use a two pass report and calculate the
    height of the memo during the first pass, then alter the dimentions of the
    shape during the second. There are numerous ways of going about this
    however the following seemed to work for me.

    1. Set the Report.PassSetting to psTwoPass.
    2. Add a private field to the class named FHeight to keep track of the memo
    height.
    3. Use the OnDrawCommandCreate events of the memo and the shape to get
    information and change dimentions.

    function TForm1.CalcDrawTextHeight(aDrawText: TppDrawText): Integer;
    var
    lCanvas: TCanvas;
    liTextHeight: Integer;
    liMemoHeight: Integer;
    liIndex: Integer;
    begin

    lCanvas := ppReport1.Printer.Canvas;
    lCanvas.Font := aDrawText.Font;
    liTextHeight := lCanvas.TextHeight('W');

    liMemoHeight := 0;

    for liIndex := 0 to aDrawText.WrappedText.Count - 1 do
    liMemoHeight := liMemoHeight + liTextHeight;

    Result := ppToMMThousandths(liMemoHeight, utPrinterPixels, pprtVertical,
    ppReport1.Printer);

    end;

    procedure TForm1.ppMemo1DrawCommandCreate(Sender, aDrawCommand: TObject);
    begin
    if ppReport1.FirstPass then
    FHeight := CalcDrawTextHeight(TppDrawText(aDrawCommand));
    end;

    procedure TForm1.ppShape1DrawCommandCreate(Sender, aDrawCommand: TObject);
    begin
    if ppReport1.SecondPass then
    TppDrawShape(aDrawCommand).Height := FHeight;
    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2009
    Hi Nico,

    Sorry for the delay in replying. Works a treat! Thank you very much!

    Best Regards

    Adam.
This discussion has been closed.