Crash Course Delphi 16 [beta]:
CSV Files - part 3

Saving your data as a CSV file

Saving your text database as a CSV file.


What should the OnClick event handler of FileSave do?

  1. Clear the listbox.
  2. Make a record-string out of each row of the stringgrid and add it to the listbox. For keeping with good modular coding practices, we'll delegate these two tasks to a separate routine, that we named AddRecToList.
  3. Save the listbox contents to a file, with the same name as from which it was loaded initially.

What should AddRecToList do with the row of a stringgrid?

  1. Start with an empty record-string.
  2. Start at column number 0 of the current row.
  3. Get the contents of the current cell into a variable for the field value.
  4. If the field contains a space or a comma, put double quotes around it.
  5. Add the field to the record-string.
  6. If more fields, then add a comma to the record-string
  7. Increment the column-counter.
  8. If more fields, repeat from step (3).
  9. When done with all the fields, add the record-string to the listbox.

 Lesson 15   Lesson 17