how do i save the text of a memo into the end of a textfile?
var f: TextFile;begin AppendFile(f,'That file you want to append'); Rewrite(f); WriteLn('A single line'); ... // more Write(Ln)(s) CloseFile(f);end;
Code: Pascal [Select][+][-]//... Rewrite(T);//...
This destroys the original contents of the file.
AssignFile(f,'file name');Append(f);... // write it outCloseFile(f);
Quote from: captain jaster on October 28, 2010, 04:54:12 pmCode: Pascal [Select][+][-]//... Rewrite(T);//...This destroys the original contents of the file.
var strum: TFileStream; tmp: string;begin tmp := 'test test test.'; strum := TFileStream.Create('file.txt', fmCreate); try strum.Seek(0, soBeginning); strum.Write(tmp[1], Length(tmp)); finally strum.Free; end;end;
var my_file: text;beginassignfile(my_file, '/home/myfile.txt'); reset(my_file); // let's open the file. If the file does not exist this will create an IOerror use the {$I-} and {$I+} with the IOresult.seek(my_file,filesize(f)); //set the pointer to last line of the file// and the next is for writing the memo lines at the end of the filefor i := 0 to Memo1.Lines.count-1 do writeln(my_file, memo1.Lines[i]); closefile(my_file);end;
Whenever possible, prefer TFileStream. It is a cleaner solution.For components, you can LoadFromFile them.