Записать или добавить текст в файл
Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch
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;
// Sample Source...
procedure TForm1.Close1Click(Sender : TObject);
var
dir, log : string;
begin
dir := ExtractFilePath(Application.Exename);
log := 'Last Programm Termination: ' + DateTimeToStr(now);
AppendOrWriteTextToFile(dir + '\logfile.txt', log)
end;
|