Link to home
Start Free TrialLog in
Avatar of cybermilky
cybermilky

asked on

Copy text from memo into text file

How to copy out all the text from a memo into a text file?
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikProg
MikProg

Memo1.Lines.SaveToFile( ... );
The easy way is to do:
  memo1.lines.savetofile('YourFileNameHere.txt');
If you want to do it the hard way you would have to do;
procedure Write;
var
  F1 : TextFile;
  i : Integer;
const
  FILENAME : string = 'C:\somefile.txt';
begin
  AssignFile(F1,FILENAME);
  Rewrite(F1);
  for i := 0 to memo1.lines.count-2 do begin
    writeLn(F1,memo1.lines.strings[i]);
  end;
  write(F1,memo1.lines.strings[i]);
  CloseFile(F1);
end;

And you just call this procedure when you need to write the text to a file.  I would use the easy way unless you are saving any header or footer information.