[Lazarus] SynEdit.Lines.LoadFromFile and non-ascii filenames

Mattias Gaertner nc-gaertnma at netcologne.de
Wed Sep 21 16:37:42 CEST 2011


On Wed, 21 Sep 2011 16:14:56 +0200
Bart <bartjunk64 at gmail.com> wrote:

> Hi,
> 
> After staring myself blind for several hours on why my program
> malfunctioned, I finally noticed a difference in behaviour between
> SynEdit.Lines.LoadFromFile and e.g. TMemo.Lines.LoadFromFile with
> regard to non-ascii characters in filenames.
> 
> As I understood it the proper way to open files, when getting the
> filename form a control like a TOpenDialog is to first convert the
> Utf8 string to Ansi/Systme-enccoding and then use this converted
> string in LoadFromFile():
> 
> begin
>   Utf8Fn := Opendialog1.Filename;
>   //convert to system encoding (I am on Windows), using FileUtils unit
>   AnsiFn := Utf8ToSys(Utf8Fn);
>   //Use converted string in LoadFromFile()
>   SynEdit1.LoadFromFile(AnsiFn);
> end;
> 
> This however throws an exception when using a filename like äbc.txt.
> The exceptionmessage is:
> Unable to open file "F:\LazarusProjecten\bugs\FileNames\?bc.txt"
> (Notice the ? in the name, this message was coverted back to Utf8 to
> show it in a TMemo)
> 
> If I do NOT convert the string first, the SynEdit loads the file just fine.
> 
> This behaviour however, is exactly the opposite of e.g TMemo, where
> you MUST convert the filename to Ansi/System encoding, or the
> LoadFromFile() will fail.

TMemo.LoadFromFile is part of the FCL, which expects system
encoding, which might not support unicode. TSynEdit is part of SynEdit
which expects UTF8 encoding. All packages in the Lazarus sources expect
UTF8 encoding.
For Delphi compatibility Lazarus uses the FCL classes.

 
> I find this a bit confusing, to say the least.

Yes.
An Unicode FCL is planned. There is slow but steady progress.

 
> Does anyone know if this behaviour (and thus the discrepancy with e.g.
> TMemo) is by design or a bug?

By design.

 
> B.t.w. I tested this behaviour on WinMe (Win9x)/vFat filesystem, and
> at first I thougt it might be just an OS issue, but the behaviour is
> the same on Win7/NTFS (Laz. r32445/Fpc 2.4.4).


Mattias




More information about the Lazarus mailing list