Ben_iti
asked on
Appending data to existing file
Appending data to existing file
var
C : String;
D : String;
F : Textfile
begin
C := #$3A+#$3B
D := #$00+#$2A
AssignFile (F, 'mama.txt');
Rewrite(F);
Writeln(F, C);
CloseFile(F);
AssignFile (F, 'mama.txt');
Append(F);
Writeln(F, D);
CloseFile(F);
end;
Every time you append to the 'mama.txt' file it tends to add a #$0D+#$0A which is exactly the same as #$0D, #$0A
From my knowledge its seems to be a [Ctrl+Z] in hex form
Does anyone know how to get rid of that extra #$0D+#$0A so that everything I append to a file is in continous line or continous string.
Ive tried this way
Assignfile (F, 'mama.txt');
Rewrite (F);
Writeln(F, C);
Writeln(F, D);
but it adds a [ASCII 26] which is not what I want
This is the extract from the Delphi Help Manual documenting the Append procedure
'If a Ctrl+Z (ASCII 26) is present in the last 128-byte block of the file, the current file position is set so that the next character added to the file overwrites the first Ctrl+Z in the block. In this way, text can be appended to a file that terminates with a Ctrl+Z.'
does anyone know how to overcome this problem?
var
C : String;
D : String;
F : Textfile
begin
C := #$3A+#$3B
D := #$00+#$2A
AssignFile (F, 'mama.txt');
Rewrite(F);
Writeln(F, C);
CloseFile(F);
AssignFile (F, 'mama.txt');
Append(F);
Writeln(F, D);
CloseFile(F);
end;
Every time you append to the 'mama.txt' file it tends to add a #$0D+#$0A which is exactly the same as #$0D, #$0A
From my knowledge its seems to be a [Ctrl+Z] in hex form
Does anyone know how to get rid of that extra #$0D+#$0A so that everything I append to a file is in continous line or continous string.
Ive tried this way
Assignfile (F, 'mama.txt');
Rewrite (F);
Writeln(F, C);
Writeln(F, D);
but it adds a [ASCII 26] which is not what I want
This is the extract from the Delphi Help Manual documenting the Append procedure
'If a Ctrl+Z (ASCII 26) is present in the last 128-byte block of the file, the current file position is set so that the next character added to the file overwrites the first Ctrl+Z in the block. In this way, text can be appended to a file that terminates with a Ctrl+Z.'
does anyone know how to overcome this problem?
Hi,
You can use Write instead of WriteLn.
Writeln adds the $0D,$0A at the end of the line.
Emmanuel
You can use Write instead of WriteLn.
Writeln adds the $0D,$0A at the end of the line.
Emmanuel
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you don't want #$0D+#$0A in every record, you must use
write(F,C);
write(F,D);
Instead of writeLN. It's because writeLN adds $0D+$0A, bur write - don't
write(F,C);
write(F,D);
Instead of writeLN. It's because writeLN adds $0D+$0A, bur write - don't
saulite, do you think that it is fair to repaet comments as answer?
i recommend that you withdraw your answer
i recommend that you withdraw your answer
ASKER
im sorry but im going to have to unaccept your answer
thanks
Ben
thanks
Ben
ASKER
Congratulations Alex
The points go to you
Your answer included further documentation on the subject.
Thanks
Ben
The points go to you
Your answer included further documentation on the subject.
Thanks
Ben
Thanks Ben. Good luck!
Alex
Alex
writeln appends alraedy$0D$0A
use write instead
#26 is allways added as file-end flag for a textfile, you can't get rid of it, if your filetyp is text.
meikl