On 16-09-2011 20:20, Arno Garrels wrote:
As far as I read this thread the OP uses a non-Unicode Delphi version. So "string" maps to AnsiString. Any assignment of an AnsiString to a WideString leads to an implicit string cast to Unicode (Win API WideCharToMultiByte) internally, that's one of the compiler 'magics' included in Delphi. Converting from Ansi to Unicode and back again to Ansi however doesn't work reliable with arbitrary binary data but only with pure _textual data, it depends on the current Ansi codepage whether or not some non-printable chars are converted back and forth without data loss.

I see. The idea is the usage of the widestring just as a easy way to call the, behind the scene, SysAllocString and SysFreeString, that we need in this case. But we can always treat it as a buffer, setting its length, and moving data, explicitly, without casting.

One could, i.e., make sure that the recieved string length doesn't
exceed a maximum and use a single call with a constant sized buffer
in order to avoid double calls.

That would work too, and it's probably the better choice, if the function gets called many times. Allocate once, use many times.

And if a EnterCriticalSection is being used, I suppose it is because
the data can change, so there is the potential the first call to get
the
size is no longer valid when requesting the data itself.
I think I mentioned that, no?

Sorry, my fault. I missed to scroll your reply till the end. I stopped in the code sample :-(
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to