browse ANSI dbf with UTF8 compiled prg

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
danca
Posts: 13
Joined: Wed Mar 16, 2016 7:09 pm

browse ANSI dbf with UTF8 compiled prg

Post by danca »

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
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: browse ANSI dbf with UTF8 compiled prg

Post by mol »

Try to define fields as functions, sth. like this:
aFields := { 'ansi2utf8(db->field1)',... }
User avatar
serge_girard
Posts: 3165
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

Post by serge_girard »

Hi Dan,

I still struggle with the same; see viewtopic.php?f=5&t=4648

Serge
There's nothing you can do that can't be done...
danca
Posts: 13
Joined: Wed Mar 16, 2016 7:09 pm

Re: browse ANSI dbf with UTF8 compiled prg

Post by danca »

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
Post Reply