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

Jonas Maebe jonas.maebe at elis.ugent.be
Wed May 11 14:05:07 CEST 2016


Graeme Geldenhuys wrote on Wed, 11 May 2016:

> I'm honestly trying very hard to understand the string changes
> implemented in FPC 3.x, and the best way to use it going forward. In
> this example I tried everything I learned from the recent mailing list
> discussions. My concern with the usage of String/AnsiString still
> stands, as this test program shows.

Your concern is with utf8string, not with string/ansistring. If you  
only use string/ansistring/unicodestring, then the behaviour of your  
program will be identical with FPC 2.6.4 and 3.0. With utf8string, the  
result is different in FPC 3.0 because now, just like when assigning  
an ansistring to a unicodestring, if you assign an ansistring to a  
utf8string the compiler will insert a code page conversion if necessary.

So yes: if you use utf8string, then your code may behave differently.  
It's not due to code page conversions in the RLT or FCL though (which  
is what you claimed before), but due to code page conversions in your  
own code.

I also think utf8string is the only such case where behaviour is  
different. Ideally, we should not have introduced that type before FPC  
3.0. Of course, hindsight is 20/20.


Jonas



More information about the fpc-pascal mailing list