Module StreamIO now no longer supports IO check
Original Reporter info from Mantis: SergeAnvarov @SergeAnvarov
-
Reporter name: Serge Anvarov
Original Reporter info from Mantis: SergeAnvarov @SergeAnvarov
- Reporter name: Serge Anvarov
Description:
The behavior of the text I/O support functions has changed and become incompatible with Delphi. The function format changed from "function (var F: TextRec): Integer" to "procedure (var F: TextRec)". If earlier the result of the function was an error code, then now it is assumed that the procedure will write the error code into InOutRes.
As a result, the implementation of the StreamIO module does not support I/O error codes.
The new implementation is made compatible with the text I/O support functions.
The patch is included, but since there are many style fixes are made, it is probably easier to replace the entire file. It is also attached.
Steps to reproduce:
{$MODE OBJFPC}
{$APPTYPE CONSOLE}
program Project1;
{$IOCHECKS OFF}
uses Classes, StreamIO;
type
TBadStream = class(TStream)
public
function Write(const Buffer; Count: LongInt): LongInt; override;
end;
function TBadStream.Write(const Buffer; Count: LongInt): LongInt;
begin
Result := 0;
end;
var
BadStream: TBadStream;
DummyFile: TextFile;
begin
BadStream := TBadStream.Create;
try
AssignStream(DummyFile, BadStream);
Rewrite(DummyFile);
try
Writeln(DummyFile, 'Some text');
if IOResult = 0 then
Writeln('No error')
else
Writeln('I/O error occurred');
finally
CloseFile(DummyFile);
end;
finally
BadStream.Free;
end;
end.
Additional information:
I do not know the reasons why text I/O support functions has been changed. It may be erroneous and easier to return the old behavior. In this case, the patch is needed not for StreamIO, but for several modules in the kernel.
Mantis conversion info:
- Mantis ID: 33043
- Version: 3.0.4
- Fixed in version: 3.1.1
- Fixed in revision: 38017 (#ea00dc02)
- Target version: 3.2.0