Home General

(Nico) RE: How do I know at RunTime whether or not the text I put into a Memo field will fit?

edited August 2010 in General
Hi Nico,

Thanks for your help, I tried to implement your solution, however, I do not
know my MemoLineCount.

I am reading a string field from my SQL query, which is generally a
paragraph of information. When I throw that text into the Memo component
via Memo.Lines.Add( ), it adds the entire paragraph to the Memo all at once
(not line by Line)...And after doing that, if I check the LineCount of the
Memo, it is always 1. It does not take any word-wrapping into
consideration. I need to know how many lines of text I have after all of
the automatic word wrapping is done in the Memo, and that I do not have...

After the text does it's automatic wrapping in the Memo [based on the Memo's
original width], and prints out.... I end up with about 25 lines of text
printing out... with about 6 more lines being truncated [but the text being
put into the Memo constantly varies - changes on every SQL record].

I need to know after it does the wrapping of the text, the height of the
Memo at that point... So that I can see if the height of that entire wrapped
text is more than my Memo's set height...

Denise

----- Original Message -----

Comments

  • edited August 2010
    Hi Denise,

    For future reference please simply reply to my response to continue the
    original thread rather than starting a new one.

    Two options.

    1. A quick and easy way to give a general idea if the text will fit would
    be to determine the entire width of the paragraph (using Canvas.TextWidth())
    and dividing that by the width of the memo. Compare that number to the
    number of lines that could fit (see my previous post). This method can
    however be inaccurate in most cases.

    2. A more accurate solution would be to manually determine how many lines
    fit into the Memo space. Luckily ReportBuilder has a utility function that
    will do most of the work for you. See the TppPlainText.WordWrap routine.
    It will populate a TStringList object which can be used to determine how
    many lines the text will occupy.

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