Archive: Need more functions (functions within functions?)


Need more functions (functions within functions?)
[EDIT]Read the bottom of my post - it seems my problem was more that OneSection doesn't work the way I want.[/EDIT]


Even though my scripts are pretty big nowadays, I would still say I'm a newbie, so bear with me...

I was wondering how I can use many instances of the same function?

I mean, in a script I'm making now, I've already used up the .onInit function, and the .onGUIInit function(the last one as a custom function).

So I hear you say, "well, why don't you just put your next function below the other inside the .onInit function?".

Well - I do that, but then the function that is "on the bottom" isn't used.

What I'm doing is that I have one function .onInit that reads from some registry strings, and does a certain thing if it finds this and that.

Now I need to put the "one section" function inside the .onInit function as well.

But when I put the "one section" function part below my other function within .onInit, the one section function doesn't work.


Here's how it looks with both functions inside .onInit:


Function .onInit
ReadRegStr $0 HKCU "Software\${VER_NAME}\Sections" "01"
${if} $0 == 1
!insertmacro UnselectSection ${Sec01}
SectionSetText ${Sec01} ""
${endif}

ReadRegStr $0 HKCU "Software\${VER_NAME}\Sections" "02"
${if} $0 == 1
!insertmacro UnselectSection ${Sec02}
SectionSetText ${Sec02} ""
${endif}

ReadRegStr $0 HKCU "Software\${VER_NAME}\Sections" "03"
${if} $0 == 1
!insertmacro UnselectSection ${Sec03}
SectionSetText ${Sec03} ""
${endif}

StrCpy $1 ${Sec04}

FunctionEnd


The StrCpy $1 ${Sec04} is for the one section function, the rest is for the other.

I've noticed that it doesn't matter if I have the StrCpy $1 ${Sec04} in there or not.

What happens when the installer is run, is that when the components page is loaded the first time, the default component is checked.
Then, if I check the optional component, they are both checked, which I don't want to happen.

This seems to be because the StrCpy $1 ${Sec04} isn't used at all.

After the initial checking of the optional component(after they are both checked), the "one section" function seems to work; when you then uncheck one, the other is checked and vice versa - but then it's a little too late, since I doubt users are going to check it more than once before they hit 'Next'.

So what if I later have an even bigger script and need a lot of different functions to happen within .onInit - how do I do it?

As I said I have made a custom function already, and if I try to make a similar one, it says it's already defined at compile time.

[EDIT]-It seems that OneSection doesn't work like I want it to - that's the problem.

I just removed the other code and only left StrCpy $1 ${Sec04} inside .onInit, and I get the same problem as before; on first load of the components page, both of those componens can be checked. I can't have that happening. Any other way?

I have tried to !include setsections.nsh that someone suggested in another thread, but even though I rename the SEC4 etc. to the section names in my script, and put the function in the same place as I now do(below all my sections), I still get "Sec04 not defined" when compiling, which I don't get using OneSection.[/EDIT]

Thanks for any help.

Attach a complete example, if you still need help.