[fpc-devel] TStringList.LoadFromFile and SavetoFile - file encoding support
Michael Van Canneyt
michael at freepascal.org
Tue Feb 3 13:14:30 CET 2009
On Tue, 3 Feb 2009, Sergei Gorelkin wrote:
> 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:
> 'cp866', 'utf-8'));
> This approach isn't limited to decoding, you can do decrypting, compressing,
> 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.
That's easily done:
- make TDecodingStream descendent of TOwnerStream (exists) and TFileStream will
- Add a second parameter to LoadFromStream(AStream : TStream; FreeStream = False)
and your call becomes
More information about the fpc-devel