I am using XE7.
I have a TMemo created in runtime.
I need enlarge your height to show all text lines.
I have tried these functions that I found on stackoverflow, but they aren´t working.
Memo.height:=get_memo_height(aMemo)
and
Memo.height:=ResizeMemo(aMemo)
I get height less than real height.
Regards, Luiz
//doesnt work
function get_memo_height(amemo:tmemo):single;
var i:integer;
astring:string;
layout:ttextlayout;
begin
Layout := TTextLayoutManager.DefaultTextLayout.Create;
astring:=”;
for i:=0 to amemo.lines.count-1 do astring:=astring+amemo.lines[i]+chr(10);
Layout.BeginUpdate;
Layout.Text :=astring;
Layout.WordWrap := amemo.wordwrap;
Layout.HorizontalAlign := amemo.TextAlign;
Layout.MaxSize := PointF(amemo.width-amemo.ContentBounds.width,maxint);
Layout.VerticalAlign := tTextAlign.taLeading;
Layout.Font := amemo.Font;
Layout.TopLeft := pointf(0,0);
Layout.EndUpdate;
result:=layout.textrect.bottom;
Layout.free;
end;
//doesnt work
function ResizeMemo(AMemo: TMemo):single;
const
Offset = 4; //The diference between ContentBounds and ContentLayout
begin
result := AMemo.ContentBounds.Height + Offset;
end;