[Lazarus] Lazarus Release 2.0.12
Luca Olivetti
luca at wetron.es
Tue Mar 2 12:13:33 CET 2021
El 2/3/21 a les 11:27, Luca Olivetti via lazarus ha escrit:
> and the fact that TMemInifile doesn't have a create method that allows
> to specify the encoding).
This is worse than I initially thought:
the only way to specify an encoding is to use a stream and a TIniFile
(with a TMemIniFile is impossible). The problem is, the TIniFile doesn't
free the stream when it is destroyed.
I couldn't find a way to specify an encoding after the fact (there's a
protected method SetEncoding but at that point it's too late since the
values have already been loaded in memory).
The best I could come up to, to emulate a TMemInifile and specify the
encoding, is to subclass TiniFile
TMyIniFile = class(TIniFile)
public
constructor Create(const fname:string);
destructor Destroy;override;
end;
constructor TMyIniFile.Create(const fname: string);
begin
inherited Create(TFileStream.Create(fname, fmOpenReadWrite),
Encoding.UTF8);
CacheUpdates:=true;
end;
destructor TMyIniFile.Destroy;
begin
inherited Destroy;
Stream.Free;
end;
and hoping that in a newer release fpc still doesn't free the stream or
uses FreeAndNil so the Stream.Free doesn't bomb out.
Bye
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007
More information about the lazarus
mailing list