1
votes

This is a clarification required to the existing post mentioned below
How to declare an Inno Setup preprocessor variable by reading from a file

Reading value from .txt file using FileOpen works perfectly fine, while reading .ini file using ReadIni returns an empty string.

The code for reading from txt file is:

#define VerFile FileOpen("common\GlobalConfig.txt")
#define AppVer FileRead(VerFile)
#expr FileClose(VerFile)
#undef VerFile

The txt file has the string Innovation.

The code for reading from ini file is:

#define AppVer ReadIni("common\GlobalConfig.ini", "Productname", "Product")

The content of the ini file is:

[Productname]
Product=Innovation

Both the files are in the same folder location.

The file is encoded with UTF-8 without BOM. I've checked with other types of encoding too, but it is returning only empty. I created with Notepad++.

Thanks in advance!

1

1 Answers

2
votes

The relative paths in ReadIni are resolved to the current working directory, what particularly in Inno Setup IDE is not the script directory.

Use absolute paths by using SourcePath predefined variable:

#define AppVer ReadIni( \
    SourcePath + "\common\GlobalConfig.ini", "Productname", "Product")

For FileOpen ISPP does that automatically, but not for ReadIni.


While not your case, another possibility is that there's something wrong with the INI file. It has to be UTF-8/ASCII without BOM or UTF-16 LE (with or without BOM).