Take the 2-minute tour ×

I've got an Inno Setuo Preprocessor array defined like this

#dim MYARRAY[3]
#define MYARRAY[0] 'foo'
#define MYARRAY[1] 'bar'
#define MYARRAY[1] 'baz'

No I would like to iterate over that array and put its contents into my translation, something like (non-working):

#define i 0

#for {i = 0; i < NUMBERELEMENTS; i++} {#MYARRAY[i]}

I found the following to be working, though, but is this the only doable way? Using i as a 'global' variable feels and simpy using a #sub feels just wrong.

#sub mysub
#for {i = 0; i < NUMBERELEMENTS; i++} mysub


What puzzled me, is that the following does not generate anything in the translation:

#define GetElement() MYARRAY[i]
#for {i = 0; i < NUMBERELEMENTS; i++} GetElement(i)

I'd expected it to generate one line of content per element of MYARRAY in the translation.

share|improve this question
Global variable (if we're talking about the MYARRAY variable in your code) is perfectly fine for this task. What is your real intention for doing all of this ? –  TLama Feb 6 '13 at 12:22
I've asked for the intention, since if you have in that array statements from a certain section, you may simply have a file with part of that section and just include this file into your current translation. –  TLama Feb 6 '13 at 12:59
The intention behind is that I #include a bunch of other files and I would like to register a function in each included file, that get's called by the one and only CurStepChanged. Currently, I do this like this: #define PREINSTALLATIONHOOKS PREINSTALLATIONHOOKS + 'File1PreInstallationHook(); ' and later in the master file if CurStep = ssInstall then begin {#PREINSTALLATIONHOOKS} end; This works, but I'd rather use an string-array item per hook instead of this single-string-concatenation. –  fawick Feb 6 '13 at 13:37
I referred to i being the global variable for the mysub-call. Changed that in the original post. –  fawick Feb 6 '13 at 13:42

1 Answer 1

up vote 0 down vote accepted

A #sub is the only thing that will work in this case. Lines can currently only be output to the translation via either a previously defined #sub or via #emit, and the latter is a statement and cannot be called from expression context.

Note that you can mitigate the "icky global variable" feel a little by using #define private i before defining your sub and #undef i after the for loop.

An issue has been filed to enhance ISPP; you could try adding your voice there if you like.

Also, I already have a script that does exactly this sort of thing (hook into CurStepChanged via #included files); it's not quite ready for public use yet but I was planning to clean it up and post it online in the next day or two. So if you can hold on for a little bit longer then you could look at or use that. (I'll edit my answer with a link once it's posted.)

share|improve this answer

Your Answer


