Skip to content
⌘ NSIS Forum Archive

Programmatically Select Sections Based on Dialog Choices?

3 posts

mojomojomojo#

Programmatically Select Sections Based on Dialog Choices?

Is it possible to programmatically select sections based on page/dialog choices?

Here's a minimal working example of something I'm trying:


!include Sections.nsh

Name "select1"
OutFile "select1.exe"
InstallDir C:\mwe
RequestExecutionLevel user

Page directory prior
Page instfiles

Function prior
!insertmacro SelectSection Level1A
FunctionEnd

Section ""
MessageBox MB_OK "Common Install"
SectionEnd

Section /o "Level 1 A" Level1A
MessageBox MB_OK "Level 1 A"
SectionEnd
Why isn't section "Level1A" ever happening? If I remove the "/o", it happens. I can insert a messagebox into "prior" and verify that it is being invoked. The docs say to use something like "${Level1A}" in the SelectSection macro, but tho NSIS compiler just complains:

unknown variable/constant "{Level1A}" detected, ignoring (macro:SelectSection:4)
I assume I'm approaching the problem incorrectly. What's wrong with what I'm doing?
Afrow UK#
As the warning shows you, Level1A is not defined when you use it. You need to move your callback function after the section in your script.

Edit: Also it should be !insertmacro SelectSection ${Level1A} but going by that warning message, that's what you have put in your actual script 😉

Stu
mojomojomojo#
Thanks. I didn't realize order was important. Perhaps I missed the part of the docs that distinguished between macros and variables and which components use what.