[Lazarus] Codepage question
Michael Van Canneyt
michael at freepascal.org
Fri Aug 15 13:57:46 CEST 2008
On Fri, 15 Aug 2008, Mattias Gaertner wrote:
> On Fri, 15 Aug 2008 13:04:44 +0200 (CEST)
> Michael Van Canneyt <michael at freepascal.org> wrote:
>
> > Hi,
> >
> > I have a DBF file which has data in some DOS codepage.
> > I'm trying to get the contents displayed correctly in Linux.
> >
> > I am aware of the 'OnTranslate' event of the TDBF component.
> > (obviously, all TStringFields have Transliterate set to True)
> >
> > I am also aware that there is some OEMToAnsi windows function
> > which - in a delphi application - does the trick: the data
> > is then displayed correctly if I do:
> >
> > function TMainForm.DBFFileTranslate(Dbf: TDbf; Src, Dest: PChar;
> > ToOem: Boolean ): Integer;
> > begin
> > OemToAnsi(Src,dest);
> > Result:=-1;
> > end;
> >
> > Obviously, this works in Delphi because Windows uses the ANSI
> > codepage.
> >
> > In lazarus (linux) this does not work. There is a space on the place
> > of special characters (german umlauts, ringel-s and so on)
> >
> > I also know Lazarus uses utf8.
> >
> > So, How do I get my dos/ansi/whatever string displayed correctly in
> > the grid?
>
> Does that mean, you want to convert a string in a specific DOS
> codepage to UTF-8 under Linux?
Yes.
> See lcl/lconvencoding.pas ConvertEncoding. With fpc2.3.1 it uses
> libiconv to convert arbitrary encodings.
> "iconv -l" gives you a list of all encoding names.
> This is somewhat slow.
> Or you can convince me that the DOS codepages should be added to the
> unit. Then you will get fast converters.
I beat you to that, the rtl has this since a very long time
(using external files, see rtl/ucmaps) and I just finished a
small program that creates include files with pascal constructs
for the character maps. So actually you don't need iconv any more.
All needed routines exist as pure pascal code.
I just started a thread on FPC Core to see how we can best structure
an interface for this in the FPC packages.
Meanwhile, I'll have a look at lconvencoding.
Michael.
More information about the Lazarus
mailing list