Page 1 of 1

XE and Unicode

Posted: Mon 18 Oct 2010 21:30
by Ingeloak
I have been experiencing several Unicode issues with Delphi XE and DevArt products. I have created an empty Firebird database. In that database, I have created a table with one field, text_val, that is a blob field of sub type 1 (memo). It is defined with the UTF8 character set. UseUnicode is true and memos are enabled in my IBC components. All three of the issues below result in a "Cannot transliterate between character sets" error message:

Issue #1 - Modifying a WideMemo field:

Code: Select all

qryText.SQL.Text := 'select * from text where id = 1';
qryText.Open;
qryText.FieldByName('text_val').AsWideString := '來電者是劫持';
qryText.Post;
Issue #2 - Updating a WideMemo field with a parameter:

Code: Select all

qryText.SQL.Text := 'update text set text_val = :newval where id = 1';
qryText.ParamByName('newval').DataType := ftWideMemo;
qryText.ParamByName('newval').AsWideString :=  '來電者是劫持';
qryText.Execute;


Issue #3 - Updating a WideMemo field with a stream:

Code: Select all

var
  Buffer: string;
begin
  Buffer := '來電者是劫持'; 
  MemStream.Write(Pointer(Buffer)^, ByteLength(Buffer));
  MemStream.Position := 0;

  qryText.SQL.Text := 'select * from text where id = 1';
  qryText.Open;
  TBLOBField(qryText.FieldByName('text_val')).LoadFromStream(Stream);
  qryText.Post;
end;

Posted: Tue 26 Oct 2010 08:26
by AndreyZ
Hello,

The point is that in RAD Studio XE the behaviour of the UnicodeToUtf8 function was changed. Therefore, we changed the behaviour of all DAC components to bypass this problem. This solution will be included in the next builds of all DAC components.

Posted: Wed 27 Oct 2010 03:10
by Ingeloak
Thanks! Also, I'd like to post a potential fix for the WideMemo parameters. In InterBaseUniProvider.pas, add the following code to CreateParamObject:

Code: Select all

function TInterBaseUniProvider.CreateParamObject(Param: TDAParam): TSharedObject;
...
      {$IFDEF VER10P} // added
        if Param.DataType = ftWideMemo then // added
          TBlob(Result).IsUnicode := True; // added
      {$ENDIF} // added
...
end;

Posted: Thu 28 Oct 2010 14:27
by AndreyZ
Thank you for your inquiry. Can you provide us a code example that might cause the error?

Posted: Thu 28 Oct 2010 15:50
by Ingeloak
The error can be produced by using the code sample in Item #2 (from the first post in this thread) along with UniDAC's InterBase provider. Here it is again:

Code: Select all

qryText.SQL.Text := 'update text set text_val = :newval where id = 1'; 
qryText.ParamByName('newval').DataType := ftWideMemo; 
qryText.ParamByName('newval').AsWideString :=  '來電者是劫持'; 
qryText.Execute;

Posted: Tue 02 Nov 2010 09:59
by AndreyZ
Thank you for the information. We fixed this problem.