Subject Re: [IBO] How to get Delphi + IBObjects to read/write in unicode to Firebird 1.5
Author cognitocognito
> Hmmm, I can't solve you problems, only share some experiences.
I've
> fiddled with it; though I lack a source of Unicode data, that
always clues
> up with me getting stuck on testing characters beyond the 7-bit
range.
>
> As long as you are in the process of trying out stuff, make sure
that both
> the default character set of the database AND the character set of
the
> connection are UNICODE_FSS. The decisions that the server makes
about the
> charset of the incoming data are dependent on the client "knowing"
what
> kind of data it is passing.
>
> In Fb 1.5, there's a bit of leeway if you hit a database or column
that's
> defined for unicode_fss with client data that is charset NONE, but
I
> haven't tested it myself. As far as I can work out, this can
simplify
> things only in the case where there's a mismatch between the
character set
> of the data and a defined default charset. It might not work where
the
> default charset of the DB is one charset while the defined charset
of the
> specific column is different.
>
> Anyway, you don't say which Firebird you're using.
>
> I don't (so far) know of any magic bullet that you can fire into
your app
> that works for both reading and writing. If everything matches up
and you
> have components that know how to display and interpret UNICODE_FSS,
then
> selects and displays with the TIBODatasets should be OK. If the
controls
> are doing their job, they should be updating the dataset properly.
>
> It's when you come to read variables into parameters that things
get a bit
> queasy sometimes. Delphi's widestring stuff doesn't cater for MBCS
wider
> than 2 bytes; unicode_fss is a fixed 3 bytes for every glyph, even
the
> 7-bit set.
>
> I seem to recall in my experiments with the Tnt controls that
reading
> values from the dataset's Fields[] array AsRawString directly into
> Params[n].Value is fine; but you may need custom xxxxSQL
properties that
> contain the introducer syntax, to get user inputs into parameter
values.
>
> There are also issues like whether the font being used in controls
is one
> that supports Unicode (not many do!) and (maybe) OEM codepage
issues (the
> codepage being the set of glyphs that the OS associates with
specific
> character codes from input devices and to output devices).
>
> Not much help, I know. It's been in my mind for a long time to do
a TI
> sheet on handling MBCS in IBO apps. I hope someone who is doing
it "for
> real" will step up and advise you (Daniel Rail?) and we can
assemble enough
> to do a demo app...but it won't be now, since I'm flat out with 3
lots of
> release notes and the organisation details of the Fb conference and
too
> short on sleep to concentrate on yet another thing.
>
> Helen
>

Thanks for you help Helen.

Just to let you know I did mention the version of Firebird I was
using in the title.

I have managed to get it all working in unicode with very few
changes. I now have japanese displaying in my system on my english
uk machine.

Leaving the database completely the same as I inherited it mainly
with charset NONE in place, I use the TNT controls and the Arial
Unicode MS font both of which I was already using and the only
difference I made to the reading and writing of the database was to
use the WideStringToUTF8String and UTF8StringToWideString from the
unicode unit from Delphi Fundamentals -
http://fundementals.sourceforge.net/unicode.html in the following
format:

paramByName('UnicodeText').AsString := WideStringToUTF8String
(TntEdit1.Text);
and
TntEdit1.Text := UTF8StringToWideString(fieldByName
('UnicodeText').AsString);

I have tested reading and writing many other non-latin characters and
they all save and re-appear correctly.

Just wanted to share this with others and hope that it might be of
some help.