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

how to get the actual height of the region at runtime?

edited March 2006 in General
Hello,
I have 3 regions inside the detail band. Here's how they look

|----------------| |----------------|
| | | |
| Region1 | | Region2 |
| | | |
|----------------| | |
| |
| |
|----------------|

|--------------------------------------|
| |
| Region3 |
| |
|--------------------------------------|


Both Region1 and Region2 contain stretchable components.
The question is how to find out these regions' height at run time to set
Region3's ShiftRelativeTo property to
Region1 or Region2 (whichever has more height) so it won't overlap Region3?
Region1 and Region2 get different heights for every detail printed.
Regards,

Gary

Comments

  • edited March 2006
    Hi Gary,

    Depending on what type of stretchable components you have inside each
    region, I would recommend trying to compare the them before printing the
    band in order to set the proper ShiftRelativeTo. For instance, if each
    region contains a number of DBMemo objects, you could retrieve the text
    before the band prints and calculate which memo will take up more space.
    Then using this information, you can set the ShiftRelativeTo property of the
    third region.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2006
    Hello Nico,
    The report is loading data from orders table and Region1 contains a
    subreport to print ordered items list (dynamic hight) and order summary
    (static height). The Region2 contains dbmemo with special notes/instructions
    (stretchable). Region3 contains terms & conditions richtext box.
    Right now I'm doing it the way you suggest - I'm checking how many ordered
    items will be printed inside Region1 and trying to calculate the height of
    the Region1 based on that information. And then I'm trying to do the same
    for Region2 by basing my calculation on the number of lines the dbmemo
    contains.
    The problem is that when users type long notes on one line instead of using
    Enter to type some of the text on a new line dbmemo returns one line while
    in fact the text gets wrapped inside the dbmemo and occupies several lines
    and ends up having more height than the Region1 while my calculations report
    it's shorter than Region1 because it has only one line of text.

    To solve this problem I need to know the actual height of dbmemo taking into
    consideration the text wrapping that may take place inside the Region2. Is
    there a way to do this? Or is there a way to know the actual size of the
    Region1 or Region2 no matter what they contain before printing Region3?

    Regards,

    Gary

  • edited March 2006
    Gary,

    Any chance you can create a group that will break for each occurrence of
    Region1/2? If so, you could then move Region 3 into the group footer and
    this will ensure that you get the result you are looking for.

    --

    Bob

  • edited March 2006
    Thanks Bob for the useful tip. I grouped the invoice by invoice number, set
    create node to false, moved the Region3 into group footer and it solved the
    problem in this case.
    Still I'd like to find out if there's a way of getting the actual hight of a
    stretchable control in case next time I can not use groups to solve
    alignment issues like this.
    Regards,

    Gary


  • edited March 2006
    Hi Gary,

    The issue is timing. An event that fires late enough to have already
    calculated the space needed for each stretchable component but early enough
    to successfully set the ShiftRelativeTo property of the third stretchable so
    it will be used is not currently available. One option would be to
    pre-calculate the space that is going to be taken by each stretchable,
    knowing the width and font sized of say a DBMemo.

    Another option would be to pre-generate the report to a "dummy" device to
    determine the height of each region before generating the report to the
    screen or printer. Creating a generic TppDevice object and connecting its
    publisher to the report's and calling PrintToDevices would do just that.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2006
    Hello Nico,
    I think the second option is a better solution. Will the region1.height
    return the actual height of the region if I check it in AfterPrint event
    handler when sending it to the dummy device?
    Thanks,

    Gary


  • edited March 2006
    Hi Gary,

    You will need to measure the actual draw command in order to get the final
    height of the region. You can use the OnDrawCommandCreate event to get
    access to the DrawCommand object. From there you are able to get the height
    of the stretched region in microns. You can use the utility routine located
    in ppUtils.pas ppFromMMThousandths to convert this value to whatever unit
    you need.

    For instance...

    uses
    ppDrwCmd,
    ppUtils,
    ppTypes;

    procedure TForm1.ppRegion1DrawCommandCreate(Sender, aDrawCommand: TObject);
    var
    lDrawShape: TppDrawShape;
    begin

    lDrawShape := TppDrawShape(aDrawCommand);

    FRegion1Height := ppFromMMThousandths(lDrawShape.Height, utInches,
    pprtVertical, nil);

    end;

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2006
    Thank you Nico for your prompt and useful replies.
    Regards,

    Gary


This discussion has been closed.