[Lazarus] TStrings, Windows and Unicode
marc.weustink at cuperus.nl
Wed Oct 24 12:39:04 CEST 2012
Howard Page-Clark wrote:
> On 24/10/12 2:25, Marcos Douglas wrote:
>> In the example below, running on Windows:
>> The name of file, after saved, is "atenÃ§Ã£o.txt" but the content is
>> I understand the filename, i.e, I need to use UTF8ToSys but I do not
>> understand the valid content.
>> procedure TForm1.Button1Click(Sender: TObject);
>> lStrings: TStrings;
>> lStrings := TStringList.Create;
>> lStrings.Text := 'atenção';
> Internally the LCL uses only UTF8 encoding, so stringlists etc. all
> expect strings in that encoding and process them correctly when supplied
A stringlist is not LCL and it does not expect anything but strings.
If you write the contents of a stringlist to a file you get bytes you
have put into the list. Nothing more nothing less.
If you want a UTF8 text file written, make sure you put UTF8 in it.
Same for reading.
When using filenames, you need to convert the name using the LCL
function LCLtoSys (or something like that)
> (as here) with a string from the IDE Editor which is also UTF8. However
> the streaming code in SaveToFile eventually calls some Windows system
> routine which does not handle UTF8 and so requires conversion from the
> UTF8 filename to be correctly handled.
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
More information about the Lazarus