diff --git a/lcl/interfaces/win32/win32proc.pp b/lcl/interfaces/win32/win32proc.pp index a298a27b4a..30453902f6 100644 --- a/lcl/interfaces/win32/win32proc.pp +++ b/lcl/interfaces/win32/win32proc.pp @@ -1278,7 +1278,8 @@ begin begin TextLen := Windows.GetWindowTextLengthW(AHandle); SetLength(WideBuffer, TextLen); - TextLen := Windows.GetWindowTextW(AHandle, @WideBuffer[1], TextLen + 1); + If TextLen > 0 // Never give Windows the chance to write to System.emptychar + Then TextLen := Windows.GetWindowTextW(AHandle, PWideChar(WideBuffer), TextLen + 1); SetLength(WideBuffer, TextLen); Result := Utf8Encode(WideBuffer); end @@ -1286,7 +1287,8 @@ begin begin TextLen := Windows.GetWindowTextLength(AHandle); SetLength(AnsiBuffer, TextLen); - TextLen := Windows.GetWindowText(AHandle, @AnsiBuffer[1], TextLen + 1); + If TextLen > 0 // Never give Windows the chance to write to System.emptychar + Then TextLen := Windows.GetWindowText(AHandle, PChar(AnsiBuffer), TextLen + 1); SetLength(AnsiBuffer, TextLen); Result := AnsiToUtf8(AnsiBuffer); end; diff --git a/lcl/interfaces/win32/win32winapi.inc b/lcl/interfaces/win32/win32winapi.inc index 2cb718a941..6d45919811 100644 --- a/lcl/interfaces/win32/win32winapi.inc +++ b/lcl/interfaces/win32/win32winapi.inc @@ -625,9 +625,9 @@ function TWin32WidgetSet.ClipboardGetOwnerShip(ClipboardType: TClipboardType; if FormatID=Windows.CF_UNICODETEXT then begin SetLength(BufferString, DataStream.Size); - DataStream.Read(BufferString[1], DataStream.Size); + DataStream.Read(PChar(BufferString)^, DataStream.Size); BufferWideString := Utf8Decode(BufferString); - BufferStream.Write(BufferWideString[1], Length(BufferString) * 2); + BufferStream.Write(PChar(BufferWideString)^, Length(BufferString) * 2); BufferStream.Position := 0; WriteStreamToClipBoard(FormatID, BufferStream); @@ -1080,7 +1080,7 @@ begin else begin SetLength(s, count); - if count > 0 then move(str^, s[1], count); + move(str^, PChar(s)^, count); end; // the length of utf8 vs Wide/Ansi the strings differ, so recalc. if UnicodeEnabledOS then @@ -1247,7 +1247,7 @@ begin else begin SetLength(s, count); - if count > 0 then move(str^, s[1], count); + move(str^, PChar(s)^, count); end; // the length of utf8 vs Wide/Ansi the strings differ, so recalc. if UnicodeEnabledOS @@ -1842,7 +1842,7 @@ begin else begin SetLength(s, count); - move(str^, s[1], count); + move(str^, PChar(s)^, count); end; // the length of utf8 vs Wide/Ansi the strings differ, so recalc. if UnicodeEnabledOS then diff --git a/lcl/interfaces/win32/win32wsdialogs.pp b/lcl/interfaces/win32/win32wsdialogs.pp index a935d399e8..c5f08f4d84 100644 --- a/lcl/interfaces/win32/win32wsdialogs.pp +++ b/lcl/interfaces/win32/win32wsdialogs.pp @@ -164,7 +164,7 @@ var begin AnsiChars:= Utf8ToAnsi(s); Result := GetMem(length(AnsiChars)+1); - Move(AnsiChars[1], Result^, length(AnsiChars)+1); + Move(PChar(AnsiChars)^, Result^, length(AnsiChars)+1); end; {------------------------------------------------------------------------------ @@ -467,7 +467,7 @@ begin else FileNameBufferSize := Length(FileNameWide); - Move(FileNameWide[1], FileNameWideBuffer^, FileNameBufferSize * 2); + Move(PChar(FileNameWide)^, FileNameWideBuffer^, FileNameBufferSize * 2); end else begin FileNameBuffer := AllocMem(FileNameBufferLen + 1);