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

Calculating Height of dynamic TPPMemos

edited October 2006 in General
Hi,

I have a report with a number of tPPMemo's, in which STRETCH is set to
"True".

During runtime, lines are added to the tPPMemo. How can I find out the
height of the tPPMemo.

(I need to do this, so I can reposition the component underneath, and resize
the component to make sure all fits in the same region).

Thanks & Regards

Adam.

Comments

  • edited October 2006
    Hi Adam,

    ReportBuilder does not calculate the vertical size of a stretchable
    component before it prints. One option would be to use the font size to
    determine the memo height before it is printed based on how many lines it
    contains. This way you would know ahead of time the height of the memo and
    would be able to position the components after it has printed.

    Another option (since you are using regions) would be to place a subreport
    below the memo inside the region and have it shiftrelativeto the memo. Then
    place all components that need to appear below the memo inside the subreport
    and they will stay below the memo regardless.

    --
    Regards,

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

    Best Regards,

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

    Thanks for your reply.


    Is it possible to get the vertical size of a stretchable component *after*
    it prints, and maybe doing a two-pass on the report?


    I could look at doing this, although I'd need to try and have some sort of
    function, as their are numerous places where this is required (not just a
    once off). Do you have an example of this please?


    Sorry - I didn't explain clearly with that. Just to clarify - when I was
    talking about regions, I was being generic (as an an area). I wasn't talking
    about tppRegions. ;-)

    Thanks & Regards

    Adam.
  • edited October 2006
    Hi Adam,


    You could generate the report to a "dummy" device initially and calculate
    the height of a dynamic object that way. In the past we have had customers
    do this to determine where a dynamic band will break or where a group will
    end. This may be overkill in your situation though.


    If you are not using regions, you could simply place a TppRegion below the
    dynamic memo with the components you want below it and set the region to
    shiftrelativeto the memo. This will keep the region and everything inside
    it properly below the memo no matter how large it gets.

    --
    Regards,

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

    Best Regards,

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

    Thanks again for your reply...


    Ahh - so the twopass function doesn't actually allow you to calculate the
    size - you'd actually have to print to a dummy device first.


    In this instance, wouldn't it just 'move' the region down, instead of
    actually shrinking the region?

    Thanks & Regards

    Adam.
  • edited October 2006
    Hi Adam,


    It would be possible to determine the height of the memo in the first pass
    but this would only be for informational purposes as it would not be
    possible to move or add any other objects successfully.


    Perhaps I'm missunderstanding what you would like your report to do.
    Placing a region below a dynamic height memo will shift the region and all
    of its contents down as the memo grows. The only way this would not work
    would be that the memo was already inside a region because RB does not
    support nested regions. Did you have something else in mind?

    --
    Regards,

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

    Best Regards,

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


    I'm using reportbuilder to create some certificates that are used by
    government authorities. The layout consists of areas, broken up into 'boxes'
    with text. The first box may contain a Location details, with name, address
    etc - and maybe anywhere from 3 to 7 lines in height. These boxes are fixed
    in width and height.

    One of the requirements is that after the text is printed, the rest of the
    box be cancelled out in the following fashion:

    A horizontal line should proceed immediately after the last line of text,
    followed by a diagnol line from top left to bottom right - filling the rest
    of the blank space in that box.

    My thought at present was to have a TppImage component, with the horizontal
    and vertical line, shift the top 'reliative to' the memo field, and resize
    the height to make sure that the diagonal line does not proceed into the
    next section (box) below.

    I'm trying to figure out a calculation to determine the height of the memo
    field, so I can both move the TppImage to the correct position, and also
    resize it so it only fills in the rest of the box, without going outside.

    Thanks & Regards

    Adam.
  • edited November 2006
    Hi Adam,

    Ok, thanks for the clarification.

    In your case you should be able to use a two pass report to measure the
    height of the memo manually then alter the image size and position based on
    that measurement. This is possible because you have a static space to work
    with. Altering dynamic height reports in the first pass can almost always
    cause problems.

    Try using the TppMemo.OnDrawCommandCreate event to find out how many lines
    of text the memo will take up. Then use the TCanvas.TextHeight to calculate
    the approximate height of the memo object. Once you have this number you
    can compare it to the height of the area the memo is in and
    resize/reposition the image accordingly. Below is a bit of psuedo code...

    uses
    ppDrwCmd;

    procedure TForm1.ppDBMemo1DrawCommandCreate(Sender, aDrawCommand: TObject);
    begin

    //access a TCanvas using a TBitmap or the printer object
    //assign the memo's font to the canvas
    //Calculate the height of some text with the same font as the memo
    (TCanvas.TextHeight('Wj');)

    try
    if ppReport1.FirstPass then
    begin
    //number of lines in the memo
    liLines := TppDrawText(aDrawCommand).WrappedText.Count;

    //calculate the approx height of the memo
    lHeight := liLines * lTextHeight;

    //move and resize the image

    end;
    end;


    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2006
    Thanks Nico!

    I'll give this a try.

    Best Regards

    Adam.



This discussion has been closed.