VarToStr lazarus / 21-General ---------------------------------------------------------------------- SymbolicFrank · 2022-11-21 14:47 It seems, that VarToStr returns a 7-bit ASCII string, while everything is UTF-8. Is that correct? And if so, do I need to use VarToUnicodeStr or VarToWideStr instead? It sounds like those return multi-byte chars. ---------------------------------------------------------------------- Zvoni · 2022-11-21 14:56 Quote from: SymbolicFrank on November 21, 2022, 03:47:56 pmIt seems, that VarToStr returns a 7-bit ASCII string, while everything is UTF-8. Is that correct? And if so, do I need to use VarToUnicodeStr or VarToWideStr instead? It sounds like those return multi-byte chars. Depends which OS: https://www.freepascal.org/docs-html/rtl/system/widestring.html https://www.freepascal.org/docs-html/rtl/system/unicodestring.html QuoteUnicodeString is a string of WideChars. The main difference with WideString is that unicodestring is reference counted, and WideString is not reference counted on Windows. But shouldn't {$H+} switch to UTF8 in any way? VarToStr returns "String" so that should be UTF8-"compatible" if {$H+} is on https://www.freepascal.org/docs-html/prog/progsu25.html Which mode are you in? Quote a {$MODE DELPHI} directive implies a {$H+} statement, all other modes switch it off. ---------------------------------------------------------------------- Thaddy · 2022-11-21 15:14 {$H+} by it self just makes it AnsiString, NOT utf8string. But in Lazarus (not fpc!) it will be treated as UTF8. Reason being that UTF8 is not a native Freepascal type. So be careful with console/terminal programs. Although for Ansi there is Ansi code page CP_UTF8. Also in FPC there is Utf8String, but as I wrote that is not a native Freepascal string type. ---------------------------------------------------------------------- SymbolicFrank · 2022-11-21 15:53 I'll try if I can find where exactly it happens, but "coupé" ends up being "coupe", after multiple conversions to/from variant to string with VarToString and vice versa (by assignment). The thing is, I don't always know the exact data type it contains, so when assigning it to a string, I always convert it up front. Just to be sure. Both files where the assignments happen are "{$mode Delphi}{$H+}". It is Windows 10 / trunk. ---------------------------------------------------------------------- Thaddy · 2022-11-21 17:02 If you can avoid variants, please do so. ---------------------------------------------------------------------- PascalDragon · 2022-11-21 22:23 Quote from: SymbolicFrank on November 21, 2022, 03:47:56 pmIt seems, that VarToStr returns a 7-bit ASCII string, while everything is UTF-8. Is that correct? And if so, do I need to use VarToUnicodeStr or VarToWideStr instead? It sounds like those return multi-byte chars. What is your platform? If it is a *nix one, did you also use either the cwstrings or fpwidestring unit in your main program? Would you please provide an example program that shows the behavior you mentioned?