Unicode text (memo) field

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
GuzunNicolae
Posts: 78
Joined: Wed 17 Jan 2007 14:16

Post by GuzunNicolae » Tue 23 Jan 2007 15:52

I changed TntDB.pas as you told me and in set_blob.txt I get normal Unicode chars, while in get_blob.txt I get '??????'

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 24 Jan 2007 07:56

This looks like the problem is not in Tnt controls. We are required a test sample to investigate this issue more detailed. Please send me a complete small sample to demonstrate it including script to create database and object(s) in it. Also specify some additional information:
- exact version of Delphi, C++ Builder or Kylix;
- exact version of MyDAC. You can see it in the About sheet of TMyConnection Editor;
- exact version of MySQL server and MySQL client. You can see it in the Info sheet of TMyConnection Editor;

GuzunNicolae
Posts: 78
Joined: Wed 17 Jan 2007 14:16

Post by GuzunNicolae » Tue 30 Jan 2007 08:42

I sent a test sample to EvgeniyD (at) crlab (dot) com

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 30 Jan 2007 15:22

Thank you for your sample. We used it for testing. There is a little inaccuracy in the code we posted before. The code below is working:

Code: Select all

function GetAsWideString(Field: TField): WideString;
var
  WideField: IWideStringField;
  Blob: TBlob;
begin
  if (Field is TMemoField) and (Field.DataSet is TCustomDADataSet) and not Field.IsNull then begin
    Blob := TCustomDADataSet(Field.DataSet).GetBlob(Field.FieldName);
    if Blob.IsUnicode then
      Result := Blob.AsWideString
    else
      Result := Blob.AsString;
    Exit;
  end;

  if Field.GetInterface(IWideStringField, WideField) then
    Result := WideField.AsWideString
  else if (Field is TWideStringField{TNT-ALLOW TWideStringField}) then begin
    if Field.IsNull then
      // This fixes a bug in TWideStringField.GetAsWideString which does not handle Null at all.
      Result := ''
    else
      Result := TWideStringField{TNT-ALLOW TWideStringField}(Field).Value
  end else
    Result := Field.AsString{TNT-ALLOW AsString};
end;

Code: Select all

procedure SetAsWideString(Field: TField; const Value: WideString);
var
  WideField: IWideStringField;
  Blob: TBlob;
begin
  if (Field is TMemoField) and (Field.DataSet is TCustomDADataSet) then begin
    Blob := TCustomDADataSet(Field.DataSet).GetBlob(Field.FieldName);
    if Blob.IsUnicode then
      Blob.AsWideString := Value
    else
      Blob.AsString := Value;
    TBlobField(Field).Modified := True;
    Exit;
  end;

  if Field.GetInterface(IWideStringField, WideField) then
    WideField.AsWideString := Value
  else if (Field is TWideStringField{TNT-ALLOW TWideStringField}) then
    TWideStringField{TNT-ALLOW TWideStringField}(Field).Value := Value
  else
    Field.AsString{TNT-ALLOW AsString} := Value;
end;

GuzunNicolae
Posts: 78
Joined: Wed 17 Jan 2007 14:16

Post by GuzunNicolae » Tue 30 Jan 2007 15:47

Thanks a lot for your patience!!!!
Finally it worked!!!!! :D

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

hehhe..

Post by eduardosic » Tue 30 Jan 2007 18:06

GuzunNicolae wrote:Thanks a lot for your patience!!!!
Finally it worked!!!!! :D
CoreLab support is the best!

Post Reply