I find that this function reads only the first byte if you pass it a stream containing Unicode characters (in Delphi XE2). Yet the DELPHI_UNICODE version of LoadFromCSV (with a TEncoding parameter) does exactly that by saving a Unicode stringlist into the stream.
In the absence of any comment from TMS I have had to solve this issue myself. LoadFromCSVStream seems to work only because (unlike all other Delphi 'loadfrom' functions) it leaves the BOM in the stream. And LoadFromCSVStream seems to require a BOM embedded at the start of the stream if you pass it a stream in other than system default encoding. It's been nearly five years since streams with different encodings became widely used in Delphi and in most of the VCL an opitonal encoding parameter has been added on stream functions. There is nothing to indicate that requiring a BOM in the stream is your alternative solution. Now that I know this, all is well, but it would be great if you could make a note to document this feature.
I could not reproduce a problem. From my tests, I can only see that LoadFromCSVStream loads as expected data with & without unicode.
Test with 2 default grids on the form:
You are correct when you say that the LoadFromCSVStream function works correctly with and without Unicode. The only failure occurs when the Unicode data in the stream does not begin with a BOM. If you construct such a stream by program (not by loading it) you will find that only the first byte is loaded, because the stream is terminated at the next zero byte. This was my initial issue.
I'm sorry but I still can't reproduce this.
This "problem" is actually due to the way this is handled in the VCL.
You will see the same behavior when you do the following:
Bruno Fierens2014-03-12 06:21:14
I give up. You will be pleased to know that this is my last posting to this thread. One last time, there is no 'problem'. I fully understand how streams work with content in different encodings. But the TMS function is really clever and magically handles streams of different types without any obvious parameter to specify the content. Unlike VCL functions which have such a parameter, it simply takes any stream, Unicode or ANSI, and works perfectly in both cases. How can this be, since the streams have completely different content? Nobody knows, because it is not documented! So before using the function, your users have to either guess, or experiment and find only one byte of data is read, or eventually work out that a BOM is essential for passing in Unicode stream content. All I am suggesting, to benefit your other users, is a dozen words of explanation, even only in the source code, of how this function was designed to work and how smart it is. It is by no means obvious, even to someone with long experience of the VCL and TMS products. Would this not be a worthwhile product improvement?
Sorry, I thought all the time you had a problem with this and insisted this was a bug.