#6 Force quotes when records read via TStTextDataRecordSet.LoadFromFile


Exported from Bugzilla, issue 3240.

--- Comment added on 5/31/2002 7:22:06 AM ---
A customer wanted to know if SysTools could help them translate a CVS file that
doesn't have its fields quoted to a CSV file where all of the fields are
quoted. I was hoping that I could use TStTextDataRecordSet.LoadFromFile to load
the records and then use TStTextDataRecord.QuoteAlways to force quotes on the
fields. However, after I trying it I saw that QuoteAlways only works when
records are being built from values. Please add the capability to force quotes
on fields when a file is read via TStTextDataRecordSet.LoadFromFile.

--- Comment added on 9/12/2002 12:39:30 PM ---
This is actually readily accomplished by setting the QuoteAlways properties of
the records prior to saving the .CSV file; some code like so accomplishes the
task (this assumes a .CSV has already been loaded into DataSet):

procedure TForm1.Button3Click(Sender: TObject);
i : Integer;
SaveDialog1.FileName := OpenDialog1.FileName;
if SaveDialog1.Execute then begin
for i := 0 to Pred(DataSet.Count) do begin
DataSet.Records[i].QuoteAlways := True;


--- Comment added on 9/12/2002 1:06:17 PM ---
Your example works for saving but the issue is with loading and, AFAICT,
QuoteAlways doesn't work when records are being loaded.

--- Comment added on 9/12/2002 2:39:11 PM ---
As I understand the original problem, the need was to convert a CSV file wherein
some fields are not quoted to one that has all fields quoted; my suggestion does

What am I missing?

--- Comment added on 9/12/2002 3:07:42 PM ---
Are you saying that they load the file, SysTools handles the data properly even
though it is inconsistently quoted, and then they can force quotes on all
records (making it consistent) by setting the flag and then saving the file?

--- Comment added on 9/12/2002 3:44:43 PM ---
When loading, quotes are used to parse the data into fields, but are otherwise
ignored (and are, in fact, stripped from the internal representation).

On OUTPUT the standard behavior is only to quote fields that contain the
separator character. This behavior can be modified by using the
DataRecord class's OnQuoteField event or via the QuoteIfSpaces or QuoteAlways

In the current architecture there's not much sense to quoting on INPUT, they'd
just be ignored internally.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks