PROBLEM WITH GREEK CHARACTERS lazarus / 16-Databases ---------------------------------------------------------------------- netapproach · 2012-05-18 11:19 I just install lazarus last version(0.9.30.4) in a Windows XP SP3 system ,and I make my first connection to an mdb file. It work just fine , but when I try to display data inside a grid or in a TDBEdit greek chars are not display propertly. I change the font to arial and the charset to GREEK_CHARSET but the problem exists again. What am I make wrong????? Please help  See a screenshot here: http://www.netapproach.gr/LAZARUS_GREEK.jpg ---------------------------------------------------------------------- ludob · 2012-05-19 14:35 You're not doing anything wrong. odbconnection uses the ansi odbc api calls instead of the unicode api calls. As a result the driver manager is converting everything to your system code page and lazarus expects utf8. If you are using a greek windows character set you can do the following in the IDE: - click on the TSQLQuery that is providing your dataset - if FieldDefs says zero items, set active to true to fill in the FieldDefs (the connection needs to be configured correctly) - double click on the TSQLQuery. The Edit fields window will pop up. Click on + and select all fields. Click on create. - click on a field that contains text data. - in the object inspector, double click on OnGetText to create a new handler and complete with the following code: Quoteprocedure TForm1.SQLQuery1yourfieldGetText(Sender: TField; var aText: string;   DisplayText: Boolean); begin   aText:=UTF8Encode(sender.AsWideString); end; - if there are more text fields, select in the field editor the other fields and set their OnGetText to the same handler When you want to save data back to the access database you'll need to do the inverse conversion in the fields OnSetText event handler. ---------------------------------------------------------------------- Zoran · 2012-05-21 13:22 Quote from: ludob on May 19, 2012, 04:35:37 pmYou're not doing anything wrong. odbconnection uses the ansi odbc api calls instead of the unicode api calls. I have the similar problem, but I cannot use the proposed solution, because I have characters which cannot be represented in system code page. Is there any workaround for that? Isn't there a way to tell odbc not to do conversion... Or, at least, can't I somehow tell odbc which ansi code page (but not what is set in windows) to use? ---------------------------------------------------------------------- ludob · 2012-05-21 13:54 QuoteIsn't there a way to tell odbc not to do conversion... Or, at least, can't I somehow tell odbc which ansi code page (but not what is set in windows) to use?The problem is that the MS odbc driver manager, the layer between the app and driver, reports all string fields as SQL_VARCHAR if the app uses the ansi ODBC api calls. Only when using the unicode ODBC api (functions end with 'W') the driver manager reports fields as SQL_WVARCHAR. The sqldb odbcconnection uses only the ansi calls. I'm updating odbcconnection now to use also the unicode api.  I'm in the middle of testing it and so far it looks good. Chinese and greek characters can be read and written to a MS Access db. There is still a need for the gettext/settext workaround because fpc will convert to the system encoding and not utf8 on windows. I'll update this thread when I upload the patch to mantis. ---------------------------------------------------------------------- netapproach · 2012-05-21 14:53 Thanks for the solution , this works just fine! ---------------------------------------------------------------------- ludob · 2012-05-21 15:18 QuoteI'll update this thread when I upload the patch to mantis. The patch is attached to http://bugs.freepascal.org/view.php?id=22095 To transform the unicode to utf8 use the following GetText and SetText event handers: Code: [Select]procedure TForm1.SQLQuery1MyUnicodeFieldGetText(Sender: TField; var aText: string;   DisplayText: Boolean); begin   aText:=UTF8Encode(sender.AsWideString); end; procedure TForm1.SQLQuery1MyUnicodeFieldSetText(Sender: TField; const aText: string); begin   sender.AsWideString:=UTF8Decode(aText); end; ---------------------------------------------------------------------- Zoran · 2012-05-22 09:14 Quote from: ludob on May 21, 2012, 05:18:49 pmQuoteI'll update this thread when I upload the patch to mantis. The patch is attached to http://bugs.freepascal.org/view.php?id=22095 To transform the unicode to utf8 use the following GetText and SetText event handers: Code: [Select]procedure TForm1.SQLQuery1MyUnicodeFieldGetText(Sender: TField; var aText: string;   DisplayText: Boolean); begin   aText:=UTF8Encode(sender.AsWideString); end; procedure TForm1.SQLQuery1MyUnicodeFieldSetText(Sender: TField; const aText: string); begin   sender.AsWideString:=UTF8Decode(aText); end; I will install fpc from trunk and apply this patch, then try the new functionality. Thank you very much, Ludob!