I'm working on some legacy software written in Delphi 7 which runs on Windows. I've minified the problem to the following program:
var f: text;
begin
assign(f, 'a.txt');
rewrite(f);
writeln(f, 'before' + chr(14) + 'after');
close(f);
assign(f, 'a.txt');
append(f);
close(f);
end.
I expect it to create a.txt
file containing "before#14after#13#10"
and then append nothing to it. However, after I run this program on Windows, I see before
in a.txt
instead, like if Delphi's append
truncates the file. If I do not re-open the file, it shows before#14after#13#10
as expected.
If I write something (FooBar
) in the re-opened file, it's appended, but as if the file was already truncated: beforeFooBar
.
This effect does not occur with any other character between 0 and 32, even with 26 (which stands for EOF).
Is this a bug in Delphi or a well-defined behavior? What is so special about chr(14)
?