[fpc-devel] Unicode support (again)
Jonas Maebe
jonas.maebe at elis.ugent.be
Mon Nov 10 17:22:10 CET 2008
On 10 Nov 2008, at 17:00, Vincent Snijders wrote:
> procedure TForm1.Button1Click(Sender: TObject);
> var
> w: widestring;
> i: integer;
> begin
> w := UTF8Decode('hallo äöü');
> Edit1.Caption := UTF8Encode(w);
Note that if the file has been saved using an UTF-8 BOM, then the
compiler will at compile time create a widestring containing the
UTF-16 version of 'hallo äöü'. If you then pass this to a function
expecting an ansistring (such as UTF8Decode), then the widestring
manager will be used to decode that string and this decoded string
will be passed to UTF8Decode. So then you'll pass an ansi-encoded
string to UTF8Decode rather than an UTF-8-encoded string (unless ansi
= utf-8 for the current execution).
It seems much more advisable to me to save the file with an UTF-8 BOM,
or even better to add {$encoding utf-8} (and/or to pass -Fcutf-8 to
the compiler) and then just use
Edit1.Caption := UTF8Encode('hallo äöü');
Jonas
More information about the fpc-devel
mailing list