Unicode (UTF-8) file reading/writing

25 views
Skip to first unread message

Zoë Peterson

unread,
Aug 2, 2026, 7:25:53 AM (5 days ago) Aug 2
to innosetup
It would be nice if any of these were implemented:

1) Pascal Script: Add an `Encoding?` or `UTF8?` parameter to
`TStrings.SaveToFile` so it can save as UTF-8 rather than ANSI.
2) Pascal Script: Add a `TStrings.ToArray: TArrayOfStrings` property to
make it easier to use SaveStringsToUTF8File.
3) ISPP: Make `ReadIni` return correct Unicode strings if the ini file
is UTF-8 encoded.

It's not that hard to work around the lack of them, but it would be nice
to not have to jump through hoops now that Inno Setup is Unicode only.

Thanks,
Zoë Peterson
Scooter Software

Martijn Laan - Inno Setup

unread,
Aug 2, 2026, 8:52:47 AM (5 days ago) Aug 2
to innosetup
Hi,

Thanks for the suggestions.

Classes like TStrings are meant to be simple wrappers around VCL classes. They don't offer all functions, but also don't introduce new ones.

TStrings.SaveToFile has an Encoding parameter in VCL, but via an overload, and overloads are not supported by our scripting engine at the moment. Nor are default values to fake an overload like this one. The lack of those is a bit annoying because it makes it hard to add new parameters to anything, might look into getting support for either at some point.

TStrings.ToArray does not exist in VCL, but there is a TStrings.ToStringArray. Should be doable, perhaps might need work to support TArray<String> as the return value when wrapping.

UTF-8 encoding is not allowed for .ini files in Windows, so the file you're talking about is not actually an .ini file. You must use UTF-16LE with BOM instead, and then it should work. Such an encoding must be set up manually, because, as documented by Microsoft, the built-in functions of Windows won't do this for you. It might work without a BOM as well, they use IsTextUnicode to detect apparently.

Greetings,
Martijn

Op 2-8-2026 om 13:25 schreef 'Zoë Peterson' via innosetup:

Zoë Peterson

unread,
Aug 3, 2026, 7:05:10 AM (4 days ago) Aug 3
to inno...@googlegroups.com
Hi Martijn,

Thank you.

> Classes like TStrings are meant to be simple wrappers around VCL
> classes. They don't offer all functions, but also don't introduce new
> ones.
> TStrings.SaveToFile has an Encoding parameter in VCL, but via an
> overload, and overloads are not supported by our scripting engine at
> the moment. Nor are default values to fake an overload like this one.
> The lack of those is a bit annoying because it makes it hard to add
> new parameters to anything, might look into getting support for either
> at some point.

With the no-overloads caveat, it probably wouldn't be worth exposing
TEncoding, but TStrings does also have a DefaultEncoding property that
would serve the same purpose.  For my specific use I have worked around
it though, and the alternative isn't significantly more complex, so it's
certainly not a pressing issue anymore.

--
Zoë Peterson
Scooter Software

Reply all
Reply to author
Forward
0 new messages