[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

Save memo lines to file.

Hi experts:
   My project will save memo lines in a file,i use
  memo1.lines.savetofile(myfilename) and it works(this function rewrite my file),my question is:if my file exists I want to append my context to my file.
It is a simple question but i can not work it out ,pls. help me.

If not FileExist(myfile) then
  savetofile(myfile)
else
  ???
0
mingwei
Asked:
mingwei
1 Solution
 
simonetCommented:
Here it goes:

begin
  if FileExists(AFileName) then
     with TStringList.create do
     try
        LoadFromFile(AFileName);
        AddStrings(Memo1.lines);
        SaveToFile(AFileName);
     finally
        free;
     end
  else
    Memo1.lines.SaveToFile(AFileName);

This will create a new file with the contents of Memo1.lines if such file doesn't exist or it will append the contents of memo1.lines to the end of the existing file.

Yours,

Alex
0
 
mingweiAuthor Commented:
Very thanks for your answer again!
I visit your web site just now,I think you should supply more tips there if you have time!
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now