Topic: Problem With TCSVWriter Enclosing Flag

Hi. I've tried to use this class in my script and the file created always seem to have the fields enclosed with the field Enclosing Char all the time, even when I have specifically entered False in the Enclosing parameter.

e.g. If I have the following code:

var
    fLogFile: TCSVWriter;
begin
    fLogFile := TCSVWriter.Create(Copy(Application.ExeName, 1, Length(Application.ExeName) - 4) + '.csv', ';', ceCrLf, False, '"');
    fLogFile.Write('Hello There');
end.

then the file contents would be:

"Hello There"

instead of the expected and wanted:

Hello There

Am I doing something wrong or is there a problem with the class functionality?

Dennis

Re: Problem With TCSVWriter Enclosing Flag

Hello.


It's strange, for me your script works correctly, please attach your project and let me know version which you use.
Double-quotes will be added automatically if in your text there is symbols like CR or LF.

Dmitry.

Re: Problem With TCSVWriter Enclosing Flag

Hi Dimiry, My mistake in the example I posted as I made that up quickly to try to show the problem without actually testing it properly.  The code given actually works as intended.
The problem can be seen in the new code below:

var
    fLogFile: TCSVWriter;
begin
    fLogFile := TCSVWriter.Create(ExtractFilePath(Application.ExeName) + 'TCSVWriter_Test.ini');
    fLogFile.Write(ExtractFilePath(Application.ExeName) + 'TCSVWriter_Test.ini');
    fLogFile.Write('TEST1');
    fLogFile.NextLine;
    fLogFile.Free;
end.

For me, the output from the  above is:

"C:\users\D\Temp\TCSVWriter_Test (MVD5.6)\TCSVWriter_Test.ini",TEST1

So it looks like it has something to do with the backslashes that are part of the path.

Dennis

Re: Problem With TCSVWriter Enclosing Flag

But in this example you don't specify Enclosing parameter


change this line

fLogFile := TCSVWriter.Create(ExtractFilePath(Application.ExeName) + 'TCSVWriter_Test.ini');

to

fLogFile := TCSVWriter.Create(ExtractFilePath(Application.ExeName) + 'TCSVWriter_Test.ini', ',', ceCrLf, False, '"');
Dmitry.

5 (edited by mr_d 2019-10-11 10:52:07)

Re: Problem With TCSVWriter Enclosing Flag

....That sort of works....but....
if in the new case of no enclosing characters seem to work now, then in the previous case of having enclosing character, why wasn't the TEST1 part that was written to the file have quotes around it?

Dennis

Re: Problem With TCSVWriter Enclosing Flag

Enclosing character will be use only if in string present symbols like space, double quotes, commas and line breaks.

Dmitry.

Re: Problem With TCSVWriter Enclosing Flag

Hmmmm...OK. I suppose if that's how it is then that's how it is. Thanks for looking into this for me. Cheers.

Dennis