I have a TMemo loaded with text. I want to choose the font size that makes the text as big as possible. The following code does not work, probably because I am mixing up the old Delphi canvas with the new TextSettings.

I have a TMemo loaded with text. I want to choose the font size that makes the text as big as possible. The following code does not work, probably because I am mixing up the old Delphi canvas with the new TextSettings.

I do not know the history, but it seems as if I am working with a mixture of old Delphi fields and some new perhaps Android fields. Can someone clarify? Even better, where would I go to read about this kind of issue without having to post a question! Searching for solutions is challenging because many "Delphi" solutions do not pertain to Android.

mw := 0;
for i := 0 to Memo1.Lines.Count-1 do begin
w := Memo1.Canvas.TextWidth(Memo1.Lines[i]);
if (w > mw) then begin
mw := w;
ml := Memo1.Lines[i]; // assumes fixed width
end;
end;
// size font so longest line fits in memo
Memo1.TextSettings.font.Size := 100;
while (Memo1.Canvas.TextWidth(ml) > width) do
Memo1.TextSettings.font.Size := Memo1.TextSettings.font.Size - 1;

Comments

Post a Comment