* Remove trailing #13#10 in the result of SysErrorMessage() on Windows and minor optimization. It is Delphi compatible.

git-svn-id: trunk@34220 -
This commit is contained in:
yury 2016-07-29 10:23:12 +00:00
parent 980c4741ac
commit e3ebaa6e6a

View File

@ -978,19 +978,22 @@ function SysErrorMessage(ErrorCode: Integer): String;
const const
MaxMsgSize = Format_Message_Max_Width_Mask; MaxMsgSize = Format_Message_Max_Width_Mask;
var var
MsgBuffer: PUnicodeChar; MsgBuffer: unicodestring;
len: longint;
begin begin
GetMem(MsgBuffer, MaxMsgSize*2); SetLength(MsgBuffer, MaxMsgSize);
FillChar(MsgBuffer^, MaxMsgSize*2, #0); len := FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nil,
nil, ErrorCode,
ErrorCode, MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT), PUnicodeChar(MsgBuffer),
MsgBuffer, MaxMsgSize,
MaxMsgSize, nil);
nil); // Remove trailing #13#10
SysErrorMessage := MsgBuffer; if (len > 1) and (MsgBuffer[len - 1] = #13) and (MsgBuffer[len] = #10) then
FreeMem(MsgBuffer, MaxMsgSize*2); Dec(len, 2);
SetLength(MsgBuffer, len);
Result := MsgBuffer;
end; end;
{**************************************************************************** {****************************************************************************