Search code examples
delphipostgresqldelphi-xe2dbgridunidac

Delphi edit unicode table data


My Delphi application using PostgreSQL database (with UniDac components). Data are stored in UTF8 in database. To read international characters, I use this handler:

procedure TdmMain.OnGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
  Text := Utf8decode (Sender.AsString);
end;

But, how possible to store data, back to DB? I created another handler, OnSetText, with Sender.AsString := Utf8Encode (Text); but it is not working.

How it is possible to do that? Thanks.


Solution

  • When reading and editing data, you don't need to recode utf-8 text by yourself (for example, in the OnGetText event). It is enough to set the UseUnicode option in the TUniConnection.SpecificOptions property to True, for example, as follows:

    UniConnection1.SpecificOptions.Values['PostgreSQL.UseUnicode'] := 'True';
    

    and UniDAC will do this automatically.

    http://www.devart.com/unidac/docs/pgsqlprov_article.htm