Prevent string conversion lazarus / 21-General ---------------------------------------------------------------------- patman · 2022-11-08 11:37 Hi. With latest Lazarus version tries to make my life much harder. Does anybody noticed huge mess with string encoding? In my old project I have to use casting as RawByteString, otherwise it is going to convert utf8 to ansi and make mess in a database. Is there any switch in a project or something like that to prevent unnecessary conversion? Thx Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i sqlUpdate := RawByteString](Format('update Kontakty set %s where Id=%s;',  [sqlSet, dsKontakt.FieldByName('PrId').AsString])); //some text - primary as utf8LoggerWrite('utf8: ' + IsUTF8String(sqlUpdate).ToString(TUseBoolStrs.True)+ ' ' + sqlUpdate); ExecuteDirect(RawByteString(sqlUpdate));LoggerWrite('ReturnString: ' + TSqlite3Dataset(Self).ReturnString); ---------------------------------------------------------------------- domasz · 2022-11-08 13:17 Side note- change names of all variables and database tables to English. Using any other language is not professional and the sooner you switch the better. You can have comments not in English but even in case of comments it would be better to use English. ---------------------------------------------------------------------- Guylain · 2022-11-08 14:50 " Using any other language is not professional": ---------------------------------------------------------------------- Jorg3000 · 2022-11-08 15:55 Hi! Is it a bug or a feature of the Format() function? Check the code page IDs of your strings using StringCodepage() ... ... StringCodepage( sqlSet ) ... StringCodepage( dsKontakt.FieldByName('PrId').AsString ) ... StringCodepage( sqlUpdate ) ---------------------------------------------------------------------- VisualLab · 2022-11-08 15:55 QuoteUsing any other language is not professional and the sooner you switch the better. Exaggeration. Any language can be used. However, if a given project is developed by many people from different countries, it is comfortably to use English names. Comfortably. Because then, usually everyone will manage somehow. There are no professional languages. English was adopted as a result of historical events (this kind of extortion by a very strong empire). And not that English should have some hypothetical qualities of professionalism. It used to be Latin (end of antiquity, middle ages). Maybe in 100-200 years it will be Chinese? P.S. I prefer English names myself. But this is out of habit. Especially if I share something with other developers. ---------------------------------------------------------------------- JuhaManninen · 2022-11-08 16:27 Quote from: VisualLab on November 08, 2022, 04:55:09 pmExaggeration. Any language can be used. +1 Usually Unicode with Lazarus works well by following these rules:  https://wiki.freepascal.org/Unicode_Support_in_Lazarus ---------------------------------------------------------------------- MarkMLl · 2022-11-08 16:45 Quote from: VisualLab on November 08, 2022, 04:55:09 pmExaggeration. Any language can be used. However, if a given project is developed by many people from different countries, it is comfortably to use English names. Comfortably. Because then, usually everyone will manage somehow. Wirth defined Pascal in English, with English reserved words. It's even rare to find non-English comments in his- or his close associates'- code. Now can we PLEASE stick to focusing on OP's question. MarkMLl ---------------------------------------------------------------------- itblumi · 2022-11-08 18:23 The compiler switch {$H+} should use AnsiStrings and they are UTF8 ---------------------------------------------------------------------- Thaddy · 2022-11-08 19:05 Quote from: itblumi on November 08, 2022, 07:23:13 pmThe compiler switch {$H+} should use AnsiStrings and they are UTF8 Of course not! CP_UTF8 is a special case for ANSI and not ANSI at all, though, since clean ANSI is a one byte notation and UTF8 is a variable notation up to 4 bytes. ---------------------------------------------------------------------- patman · 2022-11-09 09:54 Quote from: Jorg3000 on November 08, 2022, 04:55:01 pmHi! Is it a bug or a feature of the Format() function? Check the code page IDs of your strings using StringCodepage() ... ... StringCodepage( sqlSet ) ... StringCodepage( dsKontakt.FieldByName('PrId').AsString ) ... StringCodepage( sqlUpdate ) Thx for reply. StringCodepage shows me some strange behavior. I've started new project from scratch, as below. Lazarus allegedly uses utf8, but as you can see I get 1250 instead of 65001. I've got impression something is wrong with latest Lazarus compiler (lazarus 2.2.4, fpc 3.2.2), it looks like it uses default regional settings (ansi 1250) and don't care about utf8. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i varstrTest: string;beginWriteLn('const: ' + StringCodePage('test').ToString); //returns 0WriteLn('str variable: ' + StringCodePage(strTest).ToString); //returns 1250SetCodePage(RawByteString(strTest), 65001);WriteLn('StringCodePage-test: ' + StringCodePage(strTest).ToString);  //still 1250...  readln;end. ---------------------------------------------------------------------- korba812 · 2022-11-09 10:30 Are you using LCL in your project or is it a console application? If it is a console project, string uses the same encoding as Windows (1250 in your case). In this case, to get the utf-8 encoded string, add LazUTF8 unit in the uses section of main program file. https://wiki.freepascal.org/Unicode_Support_in_Lazarus#Using_UTF- 8_in_non-LCL_programs