It is required during installation to read the values ​​from one ini-file and write them to another ini-file. The function for reading a string from an ini-file for some reason returns the default value passed to it, and not the value from the file. The file is where it should be, the values ​​in it.

Here is an example script that reproduces the problem:

[Setup] AppName=MyApp AppVersion=1 DefaultDirName=D:\Projects\Test\ DisableDirPage=yes Uninstallable=no [INI] Filename: "{app}\INIFile2.ini"; Section: "Section"; Key: "Key1"; String: "{code:GetIniFileValue|'Key1'}" Filename: "{app}\INIFile2.ini"; Section: "Section"; Key: "Key2"; String: "{code:GetIniFileValue|'Key2'}" [Code] function GetIniFileValue(const Key: String): String; begin Result := GetIniString('Section', Key, 'DefaultValue', 'D:\Projects\Test\INIFile1.ini'); MsgBox(Result, mbInformation, MB_OK); // сообщение выводит результат функции GetIniString end; 

Contents of the INIFile1.ini file:

 [Section] Key1=Value1 Key2=Value2 

After the installation is completed, the INIFile2.ini file appears INIFile2.ini following contents:

 [Section] Key1=DefaultValue Key2=DefaultValue 

How do I get the values ​​from the first file?

  • Hi, there are a couple of comments about the description of the inno-setup tag. Firstly, I could not google this text, but still I will clarify: is it not copied from somewhere? Secondly, if it is opensource, it would be great to add links to the code and other resources (for example, a thematic forum or documentation). - Nick Volynkin
  • In general, thank you for organizing the information) - Nick Volynkin
  • @NickVolynkin is a translation of the description from the English version of SO. It contains more information. Added links, no longer mastered :) - kot-da-vinci
  • Excellent, accepted the edits - Nick Volynkin

1 answer 1

The error was in the transfer of parameters to the function, the parameters needed to be specified without single quotes:

 [INI] Filename: "{app}\INIFile2.ini"; Section: "Section"; Key: "Key1"; String: "{code:GetIniFileValue|Key1}" Filename: "{app}\INIFile2.ini"; Section: "Section"; Key: "Key2"; String: "{code:GetIniFileValue|Key2}" 

UPD: Found another great way to read an ini file without adding code.

 Filename: "{app}\INIFile2.ini"; Section: "Section"; Key: "Key1"; String: "{ini:{app}\INIFile1.ini,Section,Key1}"