Tuesday, December 13, 2005

D2006: New StrictDelimiter property

The TStrings class has had a new property added to it in Delphi 2006. This new property is called StrictDelimiter.

Previously if you wanted to import a CSV (comma separated file) into your Delphi application using the CommaText property on a TStringList object you had to modify the output generated from popular spreadsheet applications.

This was because some spreadsheet applications don't quote ("") items when they contain a space in the text, nor should they have to, the comma is the delimiter not the space. Finally this issue has been solved in Delphi 2006 by the addition of the StrictDelimiter property.

The property is False by default to ensure backwards compatibility.

Example Usage:

Generated with HyperDelphi

procedure TfrmMain.bLoadClick(Sender: TObject);
var
slTemp: TStringList;
begin
slTemp := TStringList.Create;
try

// load the test string into the stringlist
slTemp.CommaText := eTestString.Text;
// load the commatext value of the stringlist into the first memo
mStrictDelimiterFalse.Lines.Text := slTemp.CommaText;
// clear the previous contents of the stringlist
slTemp.Clear;
// turn on the StrictDelimiter property
slTemp.StrictDelimiter := True;
// load the test string into the stringlist
slTemp.CommaText := eTestString.Text;
// load the commatext value of the stringlist into the second memo
mStrictDelimiterTrue.Lines.Text := slTemp.CommaText;
finally
slTemp.Free;
end;
end;





Example Output:



Verify how in the first memo the three four text have a comma separating them. In the second memo, you now see that three four are grouped together. I know I consider the second memo to contain the results I want.

5 Comments:

Anonymous Anonymous said...

Jeremy,

In both IE and Firefox, your blog shows up as white text on a black background.
But the code you posted shows up as black text on a black background and very small. If the comments hadn't been in green, I wouldn't have known there was anything there.
Selecting the code makes it all white text on a grey background.
It is still too small to read, so I paste it into notepad.

2:13 AM  
Blogger JED said...

Thanks for the heads up. Hopefully it is ok now.

2:23 AM  
Anonymous Anonymous said...

Much better. Still small, but at least I can read it.

6:47 AM  
Anonymous Anonymous said...

I didn't see the original scheme, but I have to say it's still quite a strain on the eyes!
You couldn't be prevailed upon to switch to the more usual dark type on light background, could you? Or at least a heavier/larger typeface? It's a shame that your great content is fading into the night....

7:35 AM  
Anonymous Anonymous said...

(in IE) just press CTRL and SCROLL UP or DOWN to make the text bigger/smaller....

7:28 AM  

Post a Comment

<< Home