[Lazarus] Charset in TSdfDataSet

Roberto P. padovani.r at gmail.com
Thu Sep 6 14:27:35 CEST 2012


2012/9/6 GLBX <LBX at swing.be>

> **
> Right !
>
> with Textout, I get accents correctly
>
> but... when I post the changes, now, I get the problem
>
> Originally DAMMANS
>
> Changed to DéMMANS
>
> Display after editing
> DéMMANS (coorect)
>
> Saved in the CSV file as !!!!!
> DéMMANS
> and...
>
> when I display after new loading :
> DéMMANS       (!!!!?!?!?!)
>
> Oups !!
>

when working on that project of mine, I was in a hurry and I couldn't go
deeper in understanding things (like the double conversion through UTF16,
thanks Mattias).
At that time I was also UNABLE to save back to csv through the sdf dataset,
even with readonly = false, putting the db in edit/append and posting the
changes.... it looked somehow a reader-only dataset.

A quick (and maybe unefficient or dirty) trick to get around it has been to
use:
- a TSDFDataset to read the CSV file (my separtor was non-standard)
- copying it to a TMemDataset which can be manipulated really fast
- place a TCSVExporter component on the form (install in the palette from
the dbexport package) connected to the TMemDataset
When you're done with editing and posting, you can simply call
TCSVExporter.Execute to save it to CSV.

An alternative (that I couldn't explore due to the limited amount of time I
had) might be this one:  http://wiki.freepascal.org/CsvDocument
which supposedly reads and writes, either randomly (in memory) or
sequentially, a CSV file.

R#


>
> GLBX
>
> ----- Original Message -----
> *From:* Mattias Gaertner <nc-gaertnma at netcologne.de>
> *To:* Lazarus mailing list <lazarus at lists.lazarus.freepascal.org>
> *Sent:* Thursday, September 06, 2012 12:04 PM
> *Subject:* Re: [Lazarus] Charset in TSdfDataSet
>
>
> GLBX <LBX at swing.be> hat am 6. September 2012 um 11:36 geschrieben:
> > Hi,
> >
> > I checked the encodings and got :
> >
> > - GuessEncoding(dataset .fields[1].asString) and got UTF8
>  Keep in mind that it is impossible to reliably get the codepage of a
> text, unless the text begins with a BOM. GuessEncoding simply checks if the
> string validates some UTF-8 rules. If it is valid it returns UTF-8
> otherwise the system code page.
>
> > - [application]defaultTextEncoding = cp1252
> >
> > Now in DBGrid I wrote in DrawColumnCell :
> > ...
> > ExtTextOut( ....
> UTF8ToISO_8859_1(dataCSV.Fields[datacol].AsString......)
> > and.....
> > Now accents are correctly displayed...
>  It seems you are calling the windows API function ExtTextOut directly
> instead of the x-platform LCL one. The LCL one expects UTF-8, so you don't
> need the conversion.
>
> > But I will get the problem back when validating changes in fields !!!
> > (I Tried with OnSetText : but inefficient !)
>  Mattias
>
> ------------------------------
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20120906/1e14a75a/attachment-0003.html>


More information about the Lazarus mailing list