this slowpoke moves

Append String to File

function AppendOrWriteTextToFile(FileName : TFilename; WriteText : string): boolean;
var
  f : Textfile;
begin
  Result := False;
  AssignFile(f, FileName);
  try
    if FileExists(FileName) = False then
      Rewrite(f)
    else
    begin
      Append(f);
    end;
    Writeln(f, WriteText);
    Result := True;
  finally
    CloseFile(f);
  end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
var
  dir, log : string;
begin
  dir := ExtractFilePath(Application.Exename);
  log := 'Last Programm Termination: ' + DateTimeToStr(now);
  AppendOrWriteTextToFile(dir + '\a.txt', log)
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate