I wanted to get the text in a TMemo control to know if the TMemo needs a scrollbar -- To show scrollbars when it needs and to hide when no need. So I used DrawText to calculate the text's Rect in the memo, but the returned rect was incorrect !!
rcText : TRect;
hMemoDC : HDC;
hMemoDC := GetDC(memo.Handle);
DrawText(hMemoDC, PAnsiChar(memo.Text + #0), -1, rcText, DT_CALCRECT + DT_EDITCONTROL);
rcText always smaller than the actual text rect in the memo, I think it's because of each character has a different width, but this API count them by using an average width.
Now, I need the actual rect, how to do? Thank you!