reading utf8 from database
Posted: Tue 23 Oct 2007 13:28
Hi,
I'm using Delphi 7 on WIn 2k with MySQL 4.1 and MyDAC 4.30.0.11.
In the database I've tables with utf8 character set and russian characters in it.
I want to read and write these texts with my Delphi 7 application. I learned that I have to use TNT-Components and WideStrings.
I also read that I have to set MyConnection.options.useUnicode to true and that I will get my results in TWideStringFields.
So I built up a little test with
- a TNTEdit
- a simple query which should return some kyrillic words
If I'm accessing the field as a simple TStringField I get only `??????`. If I try to access the field as a TWideStringField I only get an empty string.
Any ideas? Thanks in advance
Here's the code
I'm using Delphi 7 on WIn 2k with MySQL 4.1 and MyDAC 4.30.0.11.
In the database I've tables with utf8 character set and russian characters in it.
I want to read and write these texts with my Delphi 7 application. I learned that I have to use TNT-Components and WideStrings.
I also read that I have to set MyConnection.options.useUnicode to true and that I will get my results in TWideStringFields.
So I built up a little test with
- a TNTEdit
- a simple query which should return some kyrillic words
If I'm accessing the field as a simple TStringField I get only `??????`. If I try to access the field as a TWideStringField I only get an empty string.
Any ideas? Thanks in advance
Here's the code
Code: Select all
procedure TMainEditWin.Button3Click(Sender: TObject);
var test:string;
wtest:widestring;
query:TStringlist;
begin
MainForm.MyConnection.options.useUnicode := true;
query := TStringlist.create;
query.add( 'SELECT shortDescr FROM Style where id=325108' );
MyQuery.sql := query;
MyQuery..open;
wtest := TWideStringField( MyQuery.Fields[0] ).Value;
{ result: '' }
wtest := TStringField( MyQuery.Fields[0] ).value;
{ result: '????? ?????' }
MyQuery.Close;
edTest.text := wtest;
end;