Reading from an Oracle UTF8 database

hi,
   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....
dlkingAsked:
Who is Participating?
 
LischkeConnect With a Mentor Commented:
.. 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;

begin
  StreamInfo.Base.Stream := Stream;
  if FConverter <> nil then Converter:=FConverter
                       else Converter:=RichEdit.DefaultConverter.Create;
  StreamInfo.Base.Converter:=Converter;
  try
    with EditStream do
    begin
      dwCookie := LongInt(Pointer(@StreamInfo));
      pfnCallBack := @StreamLoad;
      dwError := 0;
    end;
    StreamInfo.Swap:=False;
    case InputFormat of
      ifRTF     : TextType:=SF_RTF;
      ifRTFUnicode,
      ifUnicode : begin
                    if InputFormat = ifRTFUnicode then TextType:=SF_TEXT or SF_UNICODE or SF_RTF
                                                  else TextType:=SF_TEXT or SF_UNICODE;
                    S:=' ';
                    Stream.Read(S,SizeOf(S));
                    if (S = BOM_LSB_FIRST) or (S = BOM_MSB_FIRST) then
                    begin
                      if S = BOM_MSB_FIRST then StreamInfo.Swap:=True;
                    end
                    else Stream.Seek(-SizeOf(S),soFromCurrent);
                  end;
    else
      TextType:=SF_TEXT; // ifText
    end;
    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);
  finally
    if FConverter = nil then Converter.Free;
    if RichEdit.AutoURLDetect = adExtended then
    begin
      RichEdit.FCROld.cpMin:= 0;
      RichEdit.FCROld.cpMax:= GetWindowTextLength(RichEdit.Handle);
      RichEdit.DetectURLs(RichEdit.FCROld);
    end;
  end;
end;


This is an extended loader routine from TRichEdit98.

Ciao, Mike
0
 
LischkeCommented:
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 (www.lischke-online.de) 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
0
 
dlkingAuthor Commented:
hi,
  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
complicated?

thanks
david
0
All Courses

From novice to tech pro — start learning today.