TStream_WriteString raises EOSError with an unrelated error code when the...
Brought to you by:
twm
TStream_WriteString in u_dzClassUtils checks whether _Stream.Write wrote the whole string and, if not, calls RaiseLastOSErrorEx(GetLastError, ...). But TStream.Write is not an OS call: a memory stream or any other stream that is not backed by a file handle never sets the last error. The exception is then an EOSError with whatever error code was left over from some earlier, unrelated call.
Measured with Delphi 12 (Win32) and a TStream descendant whose Write returns 0 (like a full fixed size memory stream):
SetLastError(0): EOSError ErrorCode=0 Message=Error writing string of length 5 to stream, wrote only 0 bytes: unknown OS error (0)
SetLastError(ERROR_FILE_NOT_FOUND): EOSError ErrorCode=2 Message=Error writing string of length 5 to stream, wrote only 0 bytes: The system cannot find the file specified (2)
It should raise a stream exception instead, e.g. EWriteError as TStream.WriteBuffer does.
Fixed in revision #2422