Graeme Geldenhuys schreef:
Hello again,

We are seeing more and more "hacks" being applied to projects trying
to scramble around the missing FPC feature - no built-in Unicode
supporting.

A simple example in Lazarus.... Loading a UTF-8 encoded file into a TMemo.

Normally you would write code as follows (for ANSI text):

   Memo1.Lines.LoadFromFile('someunicodefile.txt');


Unfortunately that doesn't work if the file contains unicode content,
so the following "hack" is required which is quite nasty:

   ls := TStringList.Create;
   ls.LoadFromFile('someunicodefile.txt');
   for i := 0 to ls.Count-1 do
      ls[i] := UTF8Encode(ls[i]);
   Memo.Lines.Assign(ls);
   ls.Free



To make matters worse, things don't get clear, if mistakes like above are made.

For Lazarus it works if the file is UTF8 encoded and doesn't work if it has the system encoding<>UTF8.

If the file is UTF8 encoded,
Memo1.Lines.LoadFromFile('someunicodefile.txt');
works, currently, in Lazarus.

If the file is not UTF8 encoded - which implies, that it is not ASCII either - then you need to convert it to UTF8 before assigning it to the memo lines.

I hope, I didn't make a mistake myself here.

Vincent
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to