Archive: variable on function .oninit


variable on function .oninit
Hello
I have a problem with a script, on the .oninit function
I do the following:
Function .onInit
StrCpy $2 “name of section 4”
SectionSetText 4 "$2"
StrCpy $2 “name of section 5”
SectionSetText 5 "$2"
StrCpy $2 “name of section 6”
SectionSetText 6 "$2"

FunctionEnd
But all my section (4, 5, 6) have the name: name of section 6. I don’t understand why the variable $2 takes the last attributed value. Perhaps on the function .oninit, first the variables are calculated and then the sectionSetText are done??? I don’t know where I can do those commands, because it is to give a name to the section and this is the first executed function!!!


The sections' names are processed just before they are shown. Therefore, setting the names in .onNextPage/.onPrevPage (which are called before the page shows up, before the names are processed) might be the best solution. You won't be able to use the same variable just as before, but at least you won't have to keep a lot of variables unused until then.

I assume your example is just to show the problem, but just to be sure, you don't have to copy the string to a variable and then into the section name you can just use SectionSetName 1 "text".


tank you!
tank you!
I know that i have not to copy the string before do a sectionSetText but I have put strcpy in the exemple to simplify the problem but in fact i get the name of each section with a DLL function and i pop the value on $2 variable.
But in the script i use approximatively 10 variable for other thing (that i keep in all the script)and i have more than 16 section and subsection to named like the exemple so i can't use a different variable for each section!!!
I don't realy understand why i have to put this lines on the function .onNextPage???


I was just suggesting you will put those in .onNextPage so you will be able to use the variables else where in the script. When .onNextPage is called for the components page, push all of your variables, get the names, put them in seperate variables and set the sections names. After you have passed the components page, pop all of your variables and continue as usual. This is the best solution I can offer for you. I will try to somehow work around this for the next version of NSIS, sections names should not (IMHO) be depended on variables.