[fpc-pascal] code example where AnsiString used in FCL (SqlDB) causes data loss

Michael Van Canneyt michael at freepascal.org
Wed May 11 14:37:13 CEST 2016



On Wed, 11 May 2016, Graeme Geldenhuys wrote:

> On 2016-05-11 13:07, Michael Van Canneyt wrote:
>>
>> But what does your program prove ?
>
> See below...
>
>> You're only proving that a conversion happens when you do
>> s := fieldByName('somefield').asString;
>
> I'm proving that using the String type anywhere in the RTL and FCL is
> now terrible. If the FPC team did a search and replace (String ->
> UnicodeString) all over the RTL and FCL, then such data corrupts
> probably would not have occurred because UnicodeString is not affected
> by the running environment. Probably the exact reason why Delphi now
> using String = UnicodeString on all platforms.

It would not help if we did this: the data would be wrong in the TDataset
buffers, and the result would be worse.

I agree that the situation is currently not ideal: TString.AsString is a
problem, but it's not nowhere near as bad as you make it out to be.

You just need to know what conversions happen where, and if you do it 
works just fine.

Michael.



More information about the fpc-pascal mailing list