Archive: Problem


If section is checked, show fields
  I haven't been able to find what I'm looking for. It could be that I'm searching wrong as my English isn't the best.

Anyways, here is my problem:

I've created an installer and now there have to be some extra options. I have 4 sections and 4 fields which have to write in 2 files. A .txt file and a .cmd file.

The first 2 fields aren't a problem as they need to be filled in always. But the last to 2 fields should be hidden or grayed-out when sec04 is unchecked.

So SEC04 brings the .cmd file and then the last 2 fields are needed to fill in.

!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 6" "State" $HOST   

>!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 2" "State" $SERVER
>!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 8" "State" $DLC
>!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 10" "State" $DBMTC
>

Section "MM" SEC04 

>
So what I was thinking was something like if SEC04 is Checked then show the last 2 fields: Field 8 en Field 10.

Attached is a picture of the four fields I'm reffering to.
I hope you can help me with my sucky english :-)

If you have any questions left, let me know!

should be simple enough... use SectionGetFlags or the Sections header to check if section ${SEC04} is selected or not.
If it is not selected, then use EnableWindow <control hwnd> 0 or ShowWindow <control hwnd> 0 to disable/hide the two controls.

Depending on what you use to build the custom page, getting the control hwnd is either as simple as accessing the variable (NSDialogs), or as 'complex' as using ReadIniStr for InstallOptions(2/Ex), to completely fudging it yourself using GetDlgItem <parent dialog> <control id>.

Edit: Quick example (NSDialogs)


!include MUI.nsh
!include nsDialogs.nsh

OutFile "c:\testsetup.exe"

Page Components
Page Custom fnCreate

!insertmacro MUI_LANGUAGE "English"

Var CHECKBOX

Section "Hello" Hello
SectionEnd

Function fnCreate
nsDialogs::Create /NOUNLOAD 1018
Pop $0

${NSD_CreateCheckbox} 0 -50 100% 8u "Test"
Pop $CHECKBOX

SectionGetFlags ${Hello} $0
IntOp $0 $0 & 1 ; 1 == selected

IntCmp $0 1 _check _uncheck
_check:
${NSD_SetState} $CHECKBOX 1
goto _done
_uncheck:
${NSD_SetState} $CHECKBOX 0
_done:
nsDialogs::Show
FunctionEnd

Instead of using labels, just use LogicLib:

${If} ${SectionIsSelected} ${SectionId}
...
${Else}
...
${EndIf}


Also make sure you put this code after you define the section in your script - Animaether's code references a section with an id of ${Hello} before the actual section is defined in the script. This will not work.

I should also point out that (although if you use LogicLib, then this doesn't matter) Animaether has used the wrong operator with IntOp. It should be a single ampersand (&) and not two (&&). Two ampersands being a logical AND rather than a binary AND.

Stu

I've tried the following options:


 ConfigOptionsEtape4:

!
insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 6" "State" $HOST
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 2" "State" $SERVER
${If} ${SectionIsSelected} ${SEC04}
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 8" "State" $DLC
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 10" "State" $DBMTC
${Else}
${EndIf
and

  ConfigOptionsEtape4:

!
insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 6" "State" $HOST
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 2" "State" $SERVER
${If} ${SectionIsSelected} ${SEC04}
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 8" "State" $DLC
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 10" "State" $DBMTC
${Else}
Abort
${EndIf}
The first option didn't work. And the section option was all or nothing. When I selected the SEC04 it showed what it should, but when I didn't select SEC04 it didn't do anything at all.

Am I doing something wrong. I already had LogicLib included.

Have you got this code after the section declaration in your script?
At what point are you running this code? Before the install options page is shown?

Stu


whoops - mea culpa on the single vs double ampersands; adjusting post.

Oddly enough the code does work despite the section being declared after the function, though o_O


Originally posted by Afrow UK
Have you got this code after the section declaration in your script?
At what point are you running this code? Before the install options page is shown?

Stu
Can I PM you my script? That will probally explain a lot more I guess.

Yes if you give SectionGetFlags/SectionGetText an invalid index (in this case the string "${Hello}") then it gets the flags/text of the first section in your script.

Stu


I've used your hint, however I can't PM at. It contains to many characters.

I've got the code behind the section declaration in the Function declaration.


Mail to afrowuk tiscali co uk

Stu


Originally posted by Afrow UK
Mail to afrowuk tiscali co uk

Stu
Its on its way!

Code looks fine. Try putting a MessageBox in your If branch to see if it gets displayed depending on the section state.

Stu


I think I have found one of the problems. If you look at the code I send you, what I was talking about was line: 338 t/m 342

How ever, if I'd look a few row's down where my ini files get called, should I do something there?