To create a CSV file dynamically, you can use the following utilities called csvUtils505. They are located on:
program CsvDemo; {$ifdef fpc}{$mode objfpc} {$H+}{$endif} uses csvutils505, strwrap1; const LF = #10; // line feed for multi line cells procedure Example1; var newstr: string = ''; // buffer to hold CSV data begin // adds a cell to an existing string on row 1 CsvAddCell('test', newstr); CsvAddCell('testing 123', newstr); CsvAddCell('testing "and" 456', newstr); // row 2 starting CsvStartNewRow(newstr); CsvAddCell('tester', newstr); // row 3 starting CsvStartNewRow(newstr); CsvAddCell('testing12345', newstr); CsvAddCell('testing345', newstr); CsvAddCell('multi line '#10'cell is here', newstr); CsvAddCell('multi and another multiline '#10'cell is here', newstr); // ALWAYS END THE CSV - this cleans up and finalizes the CSV buffer CsvEnd(newstr); writeln(newstr); // save a test file StrSaveFile('testcsv.csv', newstr); writeln; writeln('Done example 1, hit enter'); writeln; readln; end; begin Example1; end.Open the file called testcsv.csv and take a look using your text editor or Excel to verify the CSV was saved as Excel compatible CSV. You can change the delimiter by using the overloaded functions that allow you to specify your own delimiter. The encloser (quote) can be specified too.