[Lazarus] TStringList.LoadFromFile encoding parameter

Michael Van Canneyt michael at freepascal.org
Mon Jul 11 10:29:08 CEST 2016



On Mon, 11 Jul 2016, Michael Schnell wrote:

> With Delphi, TStringList seems to be hard coded to use UTF16 with "Add" 
> and StringList[i] (which is a really bad idea in a String system 
> providing versatile encoding). TStringList.LoadFromFile seems do default 
> to the system ANSI encoding (which seems like rather contra-intuitive in 
> a system that defaults to coding strings as UTF16).
>
> With Lazarus, TStringList seems to be (considered to be, as 
> StrinCodePage(SomeString ) is 65001) hard coded to use UTF8 with "Add" 
> and StringList[i] (which is a bad idea, as well, but not worse than 
> Delphi forcing UTF16) TStringList.LoadFromFile uses (defaults to) "no 
> conversion" which in fact means UTF8 encoding (which in fact is straight 
> forward and obvious, and hence better than Delphi).
>
> I don't see why a redesign of the "hard coded UF8" TStringList would be 
> necessary just for setting the code of the file to be loaded by

There is no 'hard coded UTF8' stringlist.

This is an assumption made by Lazarus LCL, which - depending on the version
of FPC - sets the default single-byte string codepage to UTF8.

TStringList is not part of Lazarus, and hence must cater for other codepages
as well.

Michael.


More information about the Lazarus mailing list