[Lazarus] Charset in TSdfDataSet

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Sep 6 09:45:08 CEST 2012


On Thu, 6 Sep 2012 09:22:57 +0200
"Roberto P." <padovani.r at gmail.com> wrote:

> Hi,
> 
> I have recently dealt with a CSV file and accents.
> I concluded that the TSdfDataSet had no problem with reading the file; I
> was using a TMemo to show the strings and to see them correctly I had to
> write something like this:
> 
>    Memo.Lines.Text := UTF8Encode(SdfDataSet.Fields[0].AsString)

UTF8Encode converts a widestring to an UTF8 string. AsString returns an
ansistring. So the above first converts from system codepage to
widestring (UTF16) and then to UTF8.

 
> I'm no expert at all, especially about string encoding, so maybe someone
> else could better explain what we should with the string format in the
> DataSet and in the LCL components, but that should make you work in the
> meantime.

I'm no sdf expert, so I will assume it does no conversion like most
LCL code:

If the csv file is in UTF8 and sdf does no conversion, then you can
simply load the csv file and don't need any conversion at all.

If the csv file is in the french windows code page 1252 then you can
use the function ConvertEncoding of the LazUtils unit lconvencoding to
convert its content to UTF8 before loading it into sdf.

Mattias




More information about the Lazarus mailing list