From f43e1bfde61133b72700c8e7da8b1954206fc69f Mon Sep 17 00:00:00 2001 From: blikblum Date: Fri, 4 Nov 2016 11:32:17 +0000 Subject: [PATCH] win32: avoid redundant call for GetRealCount and GetLineStart in TWin32MemoStrings.Insert git-svn-id: trunk@53294 - --- lcl/interfaces/win32/win32memostrings.inc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lcl/interfaces/win32/win32memostrings.inc b/lcl/interfaces/win32/win32memostrings.inc index 7c9f3f5295..0cbc4090c8 100644 --- a/lcl/interfaces/win32/win32memostrings.inc +++ b/lcl/interfaces/win32/win32memostrings.inc @@ -140,24 +140,25 @@ end; procedure TWin32MemoStrings.Insert(Index: integer; const S: string); var - LineStart: Integer; + LineStart, RealCount: Integer; NewLine: String; begin - LineStart := GetLineStart(Index); - if Index < GetRealCount then + RealCount := GetRealCount; + if Index < RealCount then begin //insert with LineEnding LineStart := GetLineStart(Index); NewLine := S+LineEnding; SendMessageW(FHandle, EM_SETSEL, LineStart, LineStart); - SendMessageW(FHandle, EM_REPLACESEL, 0, lparam(PWideChar(UTF8ToUTF16(NewLine)))) + SendMessageW(FHandle, EM_REPLACESEL, 0, lparam(PWideChar(UTF8ToUTF16(NewLine)))); end else begin //append with a preceding LineEnding LineStart := GetLineStart(Index-1)+GetLineLength(Index-1); SendMessageW(FHandle, EM_SETSEL, LineStart, LineStart); - if GetRealCount = Count then + //check if last line is empty + if Get(RealCount - 1) <> '' then NewLine := LineEnding+S+LineEnding else NewLine := S+LineEnding;