[fpc-devel] TStringList.LoadFromFile and SavetoFile - file encoding support
Sergei Gorelkin
sergei_gorelkin at mail.ru
Tue Feb 3 12:33:10 CET 2009
Graeme Geldenhuys wrote:
> The point is that you will probably have a File Open dialog that gives
> the filename to TMemo.LoadFromFile. The the file dialog could collect
> the filename and optional encoding to pass on to LoadFromFile.
>
> Even if TStringList has the optional encoding parameter, prior source
> code should still work as-is without the encoding parameter. No code
> would be broken.
>
> I agree with Marco that auto detecting encodings is probably not a
> good idea in the RTL, but at least enable the option of a encoding
> parameter in TStringList, which could help things along. As in the
> case of the bug report.
>
There is no need for TStrings.LoadFromFile method at all.
The container is one matter, and its serialization is a separate one.
Just introduce a decoding stream and you can write e.g:
Strings.LoadFromStream(TDecodingStream.Create(TFileStream.Create('myfile'),
'cp866', 'utf-8'));
This approach isn't limited to decoding, you can do decrypting,
compressing, etc.
In reality, of course, you have to finalize all the stuff - that means
typing more than one line. C++ language that automatically finalizes
on-stack objects is more friendly in this respect.
Regards,
Sergei
More information about the fpc-devel
mailing list