Reading from an Oracle UTF8 database

   i'm trying to access an oracle database configured for unicode strings using delphi 3 under windows NT and using the DOA componets ver 3.31.

The test i have to be able to do is

have three records in a table

one in english
one in polish
one in japanese

and be able to display each of them.
I have played around for a few days and there are a few problems the main ones being

1) How do i get the delphi DBEDIT controls ( which are ANSI based) to show
me UNICODE characters?

2) How do i insert japanese unicode characters into the database when i cant "key them in" or cut and past them in somehow.

Any help gratefully received....
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi dlking,

well, you quickly hit the border set by the VCL regarding Unicode. Actually you have to write your own stuff, no way around it :-/

The only edit control which can show Unicode text from a database is TDBRichEdit. I'm not sure, though, if you need further adjustments to use it. I enhanced RichEdit98 (downloadable from major Delphi sites) to be data aware and it worked fine for me. The problem here is that you have explicitely to say to TDBRichEdit that you are loading Unicode otherwise it will always load ANSI text.

For the input things get worse. The VCL is so designed that no IME detection is done if your system isn't a middle east or far east version. This is pitty as you can download IMEs from Microsoft to input chinese, arabic or whatever characters. For tests you can try my UnicodeViewer ( which uses a single line RichEdit98 which is filled by clicking specific characters (or typing them if the keyboard supports them). Then you can copy the text to the clipboard and from there into your rich edit control.

Ciao, Mike
dlkingAuthor Commented:
  thanks thats helpful.
  When you say you have to explicitly tell the richedit box it is getting unicode is that through the plaintext
property or do you mean something more

.. more complicated, unfortunately. The implementation of the rich edit is somwhat buggy so you cannot set Unicode text directly (by using messages) as the end detection in the edit is still based on one null byte for the string which isn't any longer the case for Unicode (must by a 0 word).

You can use the streaming function to read in the content from a database, like:

procedure TRichEditStrings98.LoadFromStream(Stream: TStream);

var EditStream: TEditStream;
    TextType: Longint;
    StreamInfo: TRichEdit98StreamInfo;
    Converter: TConversion;

    S : WideChar;

  StreamInfo.Base.Stream := Stream;
  if FConverter <> nil then Converter:=FConverter
                       else Converter:=RichEdit.DefaultConverter.Create;
    with EditStream do
      dwCookie := LongInt(Pointer(@StreamInfo));
      pfnCallBack := @StreamLoad;
      dwError := 0;
    case InputFormat of
      ifRTF     : TextType:=SF_RTF;
      ifUnicode : begin
                    if InputFormat = ifRTFUnicode then TextType:=SF_TEXT or SF_UNICODE or SF_RTF
                                                  else TextType:=SF_TEXT or SF_UNICODE;
                    S:=' ';
                    if (S = BOM_LSB_FIRST) or (S = BOM_MSB_FIRST) then
                      if S = BOM_MSB_FIRST then StreamInfo.Swap:=True;
                    else Stream.Seek(-SizeOf(S),soFromCurrent);
      TextType:=SF_TEXT; // ifText
    if SelectedInOut then TextType:=TextType or SFF_SELECTION;
    if PlainRTF then TextType:=TextType or SFF_PLAINRTF;

    RichEdit.Perform(EM_STREAMIN, TextType, Longint(@EditStream));
    if EditStream.dwError <> 0 then raise EOutOfResources.Create(sRichEditLoadFail);
    if FConverter = nil then Converter.Free;
    if RichEdit.AutoURLDetect = adExtended then
      RichEdit.FCROld.cpMin:= 0;
      RichEdit.FCROld.cpMax:= GetWindowTextLength(RichEdit.Handle);

This is an extended loader routine from TRichEdit98.

Ciao, Mike

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.