1

I've tried multiple things that are all present in answers to this question: Can I make a TMemo size itself to the text it contains? - Firemonkey

  1. The top answer with ContentBounds.Height works... on Windows. But it does not work on Android. It's always one key press behind. Every time I press a key (be it Enter or 'f' or 'a', etc), the height is fitted to the content that was in the memo before that key was pressed.

  2. Filipe.Fonseca's answer straight up doesn't work because there is no TTextLayout hiding in the object attachment of a line. Not sure what I'm missing here.

  3. get_memo_height: This works to the extent that it's not one key press behind. But the TTextLayout uses a different Font size:

If I remove the Size setting from the StyledSettings property of the Memo then get_memo_height will produce the right height. When I do that on my phone then the Font size (as in Memo1.Font.Size, Memo1.Canvas.Font.Size and Memo1.TextSettings.Font.Size) is reported as 14.

If I add Size back in, the Font size is still reported as 14. But the Text is printed at a size of something like 16 or so.

Does anyone know where this discrepancy is coming from?

Is there a way to get the actual Font size the Memo is using while the StyledSettings are active?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
user3437976
  • 101
  • 1
  • 6
  • 1
    For #1, what about using `TThread.ForceQueue()` to delay your reading of the `ContentBounds.Height` until after the key presses are processed? – Remy Lebeau Jan 29 '20 at 17:47
  • Thanks for the tip. The delay seems to be gone But while adding empty lines at the end of the text does increase the height, removing those empty lines doesn't decrease the height. It only snaps to the right height once I remove a visible character. That's why I still prefer #3, because with that approach I can just add a character to empty lines and the textlayout will thus report the right height. But I'm currently using a hard font size of 17 for everything so for this and many other things when using styles I'd still like to know how to get a hold of the font size that is actually used. – user3437976 Jan 30 '20 at 10:40

0 Answers0