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
  ???
mingweiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.