As I told earlier, I found a bug in TStringlist. But this is general in pascal, not only Lazarus / FPC.
I have this piece of code:
program project1;
uses classes, sysutils;
var slTest : TStringlist;
slRegel : TStringlist;
index : integer;
begin
slTest := TStringlist.create;
slRegel := TStringlist.create;
try
slTest.LoadFromFile('test.txt');
slRegel.Delimiter := ';';
slRegel.QuoteChar := '"';
slRegel.StrictDelimiter := true;
for index := 0 to slTest.count - 1 do
begin
slRegel.DelimitedText := slTest[index]);
writeln(inttostr(slRegel.Count))
end;
readln();
finally
slregel.free;
sltest.free;
end;
end.
This is my textfile:
field11;field12 ;field13;field14
field21;field22 ;field23;field24
field31;"field32" ;field33;field34
field41;field42 ;field43;field44
When I run this sample, the following results in:
4
4
5
4
The reason is the double quotes together with a few spaces afterwards. TStringlist creates an extra entry.
Am I right or not?
The workaround is:
slRegel.DelimitedText := StringReplace(slTest[index],'"','',[rfReplaceAll]);
But using strictdelimiter should it work with this workaround.
It's a known problem with the stinglist, at least it's very well known to me..
it seems to work in Delphi but not in fpc when encountering spaces like that and getting an extra line inserted.
Which is why I wrote my own TlinesString class based from Tstrings. It basically works the same but it actually functions correctly.
Its does not handle strings internally like a Stringlist does but instead builds a text table as a single chunk of memory, unlike what stringlist does.
But you still need stringlist if you want to store arbitrary data in it where as what I did values like #0 are not allowed in strings as a value.
I voiced my opinion already about this and all I got was rocks thrown back at me. so here we are..
I suggest maybe writing your own parser of SPLIT does not work correctly for you in the helpers.