문제

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;
도움이 되었습니까?

해결책

Use Write instead of WriteLn.

다른 팁

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top