Forum > Beginners

Add string from Tmemo to text file

(1/1)

samoraj:
Hello, i have existing text file with information, and need to add more information in new line after existing from Tmemo. my code delete old information and i don't no how to change this

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure TForm1.SendClick(Sender: TObject);begin       AssignFile(F, '\\SERVICEII-PC\print\sram\'+ ComboBox2.Text +'.txt');     Rewrite(F);     CloseFile(F);      TempStrings := TStringList.Create;      TempStrings.AddStrings(Memo2.Lines);       TempStrings.SaveToFile('\\SERVICEII-PC\print\sram\'+ComboBox2.Text+'.txt');       TempStrings.Free; end;      

Thaddy:
You close the file.... If you want to append, use a TFilestream.

howardpc:
There are numerous ways to accomplish what you want. Here's one:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.SendClick(Sender: TObject);var  sl: TStringList;  filename: String;   function GetFileName: string;  const    TextFilePath = '\\SERVICEII-PC\print\sram\';  begin    Exit(TextFilePath + ComboBox2.Text + '.txt');  end; begin  filename:=GetFilename;  if not FileExists(filename) then    Exit;  sl:=TStringList.Create;  try    sl.LoadFromFile(filename);    sl.AddStrings(Memo2.Lines);    sl.SaveToFile(filename);  finally    sl.Free;  end;end;

samoraj:
Thanks  howardpc   ::)

Navigation

[0] Message Index

Go to full version