Use Write
instead of WriteLn
.
Write in textfile in Delphi
-
28-06-2022 - |
Question
hi i am trying to make a delphi program that writes to a text file so far failed to achieve all but one detail is that the program writes well when used several times
hi
hi
hi
and I need to do so
hihihi
the code that I have so far is this
TForm1.Button1Click procedure (Sender: TObject);
var
File: TextFile;
begin
AssignFile (file, 'aca.txt');
/ / FileMode: = fmOpenWrite;
if FileExists ('aca.txt') then
Append (file)
else
Rewrite (file);
Writeln (file, 'hi');
CloseFile (file);
end;
Solution
OTHER TIPS
Try TStrings
var
ALines: TStrings;
begin
ALines := TStringList.Create;
try
ALines.LoadFromFile('textfile.txt');
Alines.Add('New Content');
ALines.SaveToFile('textfile.txt');
finally
ALines.Free;
end;
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow