[Lazarus] SynEdit.Lines.LoadFromFile and non-ascii filenames
Bart
bartjunk64 at gmail.com
Wed Sep 21 16:14:56 CEST 2011
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.
I find this a bit confusing, to say the least.
Does anyone know if this behaviour (and thus the discrepancy with e.g.
TMemo) is by design or a bug?
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).
Bart
More information about the Lazarus
mailing list