من کدم رو به این شکل نوشتم و مورد حل شد.
Procedure AddLineToMemo(Memo : TMemo; S : String);
// 97-10-28
function GetVisibleLineCount(Memo: TMemo): Integer;
var
DC: HDC;
SaveFont: HFONT;
TextMetric: TTextMetric;
EditRect: TRect;
begin
DC := GetDC(0);
SaveFont := SelectObject(DC, Memo.Font.Handle);
GetTextMetrics(DC, TextMetric);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
Memo.Perform(EM_GETRECT, 0, LPARAM(@EditRect));
Result := (EditRect.Bottom - EditRect.Top) div TextMetric.tmHeight;
end;
var
LineCount, TopLine, VisLines: Integer;
NoSCRL : Boolean ;
begin
LineCount := Memo.Perform(EM_GETLINECOUNT, 0, 0) - 1;
TopLine := Memo.Perform(EM_GETFIRSTVISIBLELINE, 0, 0);
VisLines := GetVisibleLineCount(Memo);
settings.Label32.caption := 'Top= ' + IntToStr(TopLine) + ' Count= ' + IntToStr(LineCount)+ ' Vis Line Count= '+ IntToStr(VisLines);
NoSCRL := (TopLine + VisLines) <= LineCount;
if NoSCRL then Memo.Lines.BeginUpdate;
memo.Lines.Add(s);
if NoSCRL then Memo.Lines.EndUpdate;
end;
اما حالا یه مورد دیگه داره.
و اون اینکه در موقعیکه خطوط افزوده میشود و بخواهم یک بخشی از تکس رو سلکت کنم ، با آمدن و اضافه شدن خطوط جدید، سلکت من خراب میشه و از دست میره.
چطور میشه حلش کرد؟