Hi all, I'm facing some headaches with ANSI/UTF8 conversion.
How can I display correctly a dbf with ANSI coded words in a UNICODE compiled program?
I have databases with data in ANSI format. (I also need to read text files UTF8 coded)
I managed to read txt files, convert the text and save it in ANSI. So far so good. When I read a string from database I convert in UTF8 because msgInfo et. al. seem to need UTF8. Ok.
But browse() is another beast.
I tried to change codepage before the browse:
REQUEST HB_CODEPAGE ITWIN //(or ITISO)
...
HB_CDPSELECT("ITWIN") // or ITISO
BROWSE()
The accented words are not displayed correctly.
Is it possible to have browse() to read ANSI data and display correctly in a UTF8 compiled program?
I am from Italy and my Windows is using ANSI 8859 codepage, as far as I know.
Dan
browse ANSI dbf with UTF8 compiled prg
Moderator: Rathinagiri
Re: browse ANSI dbf with UTF8 compiled prg
Try to define fields as functions, sth. like this:
aFields := { 'ansi2utf8(db->field1)',... }
aFields := { 'ansi2utf8(db->field1)',... }
- serge_girard
- Posts: 3166
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: browse ANSI dbf with UTF8 compiled prg
There's nothing you can do that can't be done...
Re: browse ANSI dbf with UTF8 compiled prg
Thanks for the feedback.
At present I recompiled the program with ANSI library then put simply:
REQUEST HB_CODEPAGE_ITISO
...
HB_CDPSELECT("ITISO")
Now if I read a text file UTF-8 coded I use hb_utf8toStr(cstring) -> string correctly converted. Ok that's a temporary workaround.
After googling around and reading about various codepage-related doubts in other newsgroups/forums I better focused my problem (hopefully).
The point is, I have databases ANSI coded and I don't want to switch them to UTF-8. If the program is compiled with UTF-8 library maybe the correct way can be something like:
SET (_SET_DBCODEPAGE ,"ITISO") or SET (_SET_DBCODEPAGE,hb_cdpOS())
This should assure that databases are treated "as usual".
Then I need a conversion from ansi to UTF-8 only for data display:
HB_SETTERMCP("ITISO","UTF-8")
I'll try and report the results of my findings...
@ mol: this is going to be complicated... I hope to find a less invasive solution!
Dan
At present I recompiled the program with ANSI library then put simply:
REQUEST HB_CODEPAGE_ITISO
...
HB_CDPSELECT("ITISO")
Now if I read a text file UTF-8 coded I use hb_utf8toStr(cstring) -> string correctly converted. Ok that's a temporary workaround.
After googling around and reading about various codepage-related doubts in other newsgroups/forums I better focused my problem (hopefully).
The point is, I have databases ANSI coded and I don't want to switch them to UTF-8. If the program is compiled with UTF-8 library maybe the correct way can be something like:
SET (_SET_DBCODEPAGE ,"ITISO") or SET (_SET_DBCODEPAGE,hb_cdpOS())
This should assure that databases are treated "as usual".
Then I need a conversion from ansi to UTF-8 only for data display:
HB_SETTERMCP("ITISO","UTF-8")
I'll try and report the results of my findings...
@ mol: this is going to be complicated... I hope to find a less invasive solution!
Dan