I am using the latest version of Lazarus IDE and I have a Memo1 on my TForm1. I have to load a text file in Memo1 and then edit every line of the Memo (I use Memo1.Lines.Strings[i] := ...). At the end I must save the edited memo at a particular path.
Question: I am looking for the faster way between:
- Load the whole text inside the memo, edit its content and save into a new file (load all -> edit all -> write all)
- Do a
whileloop (until the end of my*.txtfile) that reads the file line by line, edit the content and save it in the new file. (load line -> edit -> write | load -> edit -> write | load line -> edit -> write | ...)
I am pretty new with Delphi developing, and I have also read some pages about TStringLists. My text file is going to have a lot of lines (It could have 5000+ lines) and I don't want that my program loses performance.
Any suggestion? Should I use TStringList or one of the two methods I listed before?
5000lines isn't a lot, unless the strings are very long.The easiest way is to use a
TStringList. There's no need to use a GUI control unless the user needs to see or edit the content.If (as you say in a comment above) you need to do this in a
TMemofor testing purposes, you can do it the same way:Of course, the easiest way to do this would be to write a procedure that accepts a plain
TStringsdescendent of any sort:Then you can call it with either one: