I'm trying to create a custom page via nsDialog, with radio buttons that then affect a section further on. The issue I have is that the values do not seem to propagate beyond the CustomPage
funtion, seen in the example below:
Var RADIO_APPLE
Var RADIO_BANANA
Function CustomPage
nsDialogs::Create 1018
${NSD_CreateRadioButton} 0 0 100% 10u "Apple"
Pop $RADIO_APPLE
${NSD_CreateRadioButton} 0 20 100% 10u "Banana"
Pop $RADIO_BANANA
${NSD_Check} $RADIO_APPLE
nsDialogs::Show
${NSD_GetState} $RADIO_APPLE $0
${NSD_GetState} $RADIO_BANANA $1
MessageBox MB_OK "Apple $0 Banana $1"
FunctionEnd
Section "-CustomSection"
${NSD_GetState} $RADIO_APPLE $0
${NSD_GetState} $RADIO_BANANA $1
MessageBox MB_OK "Apple $0 Banana $1"
SectionEnd
This is obviously a gist, ignoring the includes and other pages, but when I build the full version of this I see
Apple 1 Banana 0
on the message box raised inside CustomPage
, but see
Apple 0 Banana 0
when the section is run.
I've read through https://nsis.sourceforge.io/NsDialogs_FAQ#How_to_easily_handle_radiobutton_selections and this solution gives me the same outcome.
Is there something I'm missing to make $RADIO_*
available in the section?
Thanks
You should not store important long-lasting state in the registers, especially in $0 because it is used by other pages and plug-ins. The components page for example uses $0 in one of the callback functions.
Your checkbox handles on the other hand are only used on that page so you could use $1 and $2.
The other issue is, you can't rely on reading control data after nsDialogs::Show
returns. You are supposed to use the leave callback to validate and store user input.
!include nsDialogs.nsh
Page Custom MyCreate MyLeave
Page InstFiles
Var Apple
Var Banana
Function .onInit
StrCpy $Banana 1 ; Make banana the default
FunctionEnd
Function MyCreate
nsDialogs::Create 1018
Pop $0
${NSD_CreateRadioButton} 0 0 100% 10u "Apple"
Pop $1
${NSD_CreateRadioButton} 0 20 100% 10u "Banana"
Pop $2
${NSD_SetState} $1 $Apple
${NSD_SetState} $2 $Banana
nsDialogs::Show
FunctionEnd
Function MyLeave
${NSD_GetState} $1 $Apple
${NSD_GetState} $2 $Banana
FunctionEnd
Section "-CustomSection"
MessageBox MB_OK "Apple $Apple Banana $Banana"
SectionEnd