Archive: .onSelChage Statement


.onSelChage Statement
I don't see what is wrong with this logic? no matter what section I click my if statement is always getting hit (popup box is coming up), and I am not getting the results I want to. Why is this not valid, I am simply trying to get the value of one section and if it's selected then select 2 other sections.

thanks,

Function .onSelChange

SectionGetFlags MySection $0
${If} $0 == ${SF_SELECTED}
MessageBox MB_OK "I CLICKED!"
SectionSetFlags MySection2 $0
SectionSetFlags MySection4 $0
${EndIf}

FunctionEnd


Use ${If} ${SectionIsSelected} ${MySection}. There are three possible reasons your code does not work. You are missing ${} around MySection, your section exists later on your script (and MySection is not yet defined) or $0 contains more than just the ${SF_SELECTED} flag which is why you should use the SectionIsSelected macro or check the flag using IntOp.

Edit: And don't just use SectionSetFlags like that; it'll overwrite any existing flags. Use the macros in Section.nsh like I have told you.

Stu


Sorry my bad...


I've explained this on the forum before but...
Section `My Section` MySection
...is the same as...
!define MySection [section_index]

You cannot use ${MySection} before it has been defined in the script. That is why you get "unknown variable/constant". If you want to avoid using the define, just use the (zero based) section index instead. Be aware that adding more sections though will break your code.

Stu


I changed it to a numbered index.

${If} ${SectionIsSelected} 0
MessageBox MB_OK "I CLICKED!"
!insertmacro SelectSection 2
!insertmacro SelectSection 4
${EndIf}

Still I click any of the other sections the messagebox still appears.

I have 7 sections total, now by index based 0, section 1 and 3 are not un-selectable at all however the messagebox still appears.


Yes... because section 0 is selected. If you unselect section 0 your message box will not show. You will need an additional state variable in order to detect a particular section has been selected or unselected.

Also I really do recommend you stick to using the section defines.
Section `My Section` MySection
...
${If} ${SectionIsSelected} ${MySection}

Notice I have them after each other. Just move your .onSelChange function to the end of your script.

Stu


I am using the MUI_FUNCTION_DESCRIPTION defined, and I am trying to use that section define for this, $(SECTION_Mysection), I have my script broken over several files and I have put .onSelChange after a bunch of other uninstall stuff in my uninstaller.nsi. I am still not getting what I am looking for.


Finally got this working,

thanks,

Is there a way to tell if a section is not selected using the ! for SectionIsSelected or is this going to screw up and not work?


Nevermind IfNot works thanks,