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

how do I know at RunTime whether or not the text I put into a Memo field will fit?

edited August 2010 in General
I have a situation where I am printing a TppMemo in a DetailBand, and I
cannot let the Memo expand. It needs to be Static (a set height, and never
stretch).

In certain situations, however, the text I try to put into the Memo
component at RunTime will not fit within the given height/space for that
Memo component. What I want to do is try to put the text into the Memo [at
runtime] via the Memo.Add.Lines( ) procedure, and then I want to know
immediately [before printing] whether all of my text is going to fit in that
Memo or whether or not it will truncate.

Right now it truncates the text, obviously, but that is not the desired
result. I want to know right away [in the DetailBandBeforePrint( )] whether
or not the text will fit, so that if it does not --- I can then wipe out the
Memo text and put something else in there instead (such as a warning
'Insufficient space for printing', or something similar).

Is there a way I can tell right after putting the text into the Memo at
RunTime whether or not there is enough space for that desired text?

Denise Mace
dmace@computrition.com

Comments

  • edited August 2010
    Hi Denise,

    If you are using the Memo.Lines.Add() routine, you must be adding the
    desired text line by line. In this case you can measure how much space the
    text will take using the TCanvas.TextHeight() routine.

    For instance...

    //Get the height of the text
    lBitmap := TBitmap.Create;
    lBitmap.Canvas.Font := ppMemo.Font;
    liTextHeight := lBitmap.Canvas.TextHeight('W') * MemoLineCount;

    //Get the height of the memo
    liMemoHeight := ppMemo.Height; //you may need to convert this value

    //Determine if the text will fit
    Result := liMemoHeight >= liTextHeight;


    Use the ppToScreenPixels routine located in the ppUtils.pas file to convert
    the Memo.Height to the proper units.

    --
    Regards,

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

    Best Regards,

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