Archive: Why don't my radio buttons work?


Why don't my radio buttons work?
  Hi all,

I have 2 radio buttons in a page, I don't know why the states of the 2 radio buttons are set to 1 or 0 at the same time, which are checked in 'pageLeave' function, even if only 1 button is selected. Here is the function for the page. Please help. Thanks in advance.


unction OptionServerClient


nsDialogs
::Create /NOUNLOAD 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateGroupBox} 0u 13u 85% 45% "Please select one of the following installation options:"
Pop $0

!define NSD_ADD_STYLE ${WS_GROUP}

${NSD_CreateRadioButton} 10 25u 40% 12u "&Server"
Pop $RadioButtonServer
${NSD_AddStyle} $RadioButtonServer ${WS_GROUP}

MessageBox MB_OK "$$RadioButtonServer_State=$RadioButtonServer_State $$RadioButtonClient_State=$RadioButtonClient_State$\n"

${If} $RadioButtonClient_State != 1
SendMessage $RadioButtonServer${BM_SETCHECK} ${BST_CHECKED} 0
${EndIf}

${NSD_CreateRadioButton} 10 45u 40% 12u "&Client"
Pop $RadioButtonClient
${NSD_AddStyle} $RadioButtonClient ${WS_GROUP}
; ${NSD_SetState} $RadioButtonClient ${BST_UNCHECKED}

# alternative for the above ${If}:
#${NSD_SetState} $Checkbox_State

nsDialogs::Show

FunctionEnd

>Function OptionServerClientPageLeave

${NSD_GetState} $RadioButtonServer $RadioButtonServer_State
${NSD_GetState} $RadioButtonServer $RadioButtonClient_State
MessageBox MB_OK "$RadioButtonServer_State - $RadioButtonClient_State$\n"
>FunctionEnd
>

    nsDialogs::Create /NOUNLOAD 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateGroupBox} 0u 13u 85% 45% "Please select one of the following installation options:"
Pop $0

!define NSD_ADD_STYLE ${WS_GROUP}

${NSD_CreateRadioButton} 10 25u 40% 12u "&Server"
Pop $RadioButtonServer
${NSD_AddStyle} $RadioButtonServer ${WS_GROUP}

MessageBox MB_OK "$$RadioButtonServer_State=$RadioButtonServer_State $$RadioButtonClient_State=$RadioButtonClient_State$\n"

${If} $RadioButtonClient_State != 1
SendMessage $RadioButtonServer ${BM_SETCHECK} ${BST_CHECKED} 0
${EndIf}

${NSD_CreateRadioButton} 10 45u 40% 12u "&Client"
Pop $RadioButtonClient
; ${NSD_AddStyle} $RadioButtonClient ${WS_GROUP}
; ${NSD_SetState} $RadioButtonClient ${BST_UNCHECKED}

# alternative for the above ${If}:
#${NSD_SetState} $Checkbox_State

nsDialogs::Show

FunctionEnd

Function OptionServerClientPageLeave

${NSD_GetState} $RadioButtonServer $RadioButtonServer_State
${NSD_GetState} $RadioButtonServer $RadioButtonClient_State
MessageBox MB_OK "$RadioButtonServer_State - $RadioButtonClient_State$\n"

Hi Red Wine,
Did you forget to post something else? It seems to be the same as mine. Anyway, Thanks for your reply.


It's not the same, you haven't look closely in the code.
I just added a comment in ${NSD_AddStyle} $RadioButtonClient ${WS_GROUP}.

Anyway the code is a bit messed. Also if this not the 1st page of the sequence, you should preserve its state in case the back button is pressed.

Here is my scenario:

Function OptionServerClient

nsDialogs::Create /NOUNLOAD 1018
Pop $0

${IfThen} $0 == error ${|} Abort ${|}

${NSD_CreateGroupBox} 0u 13u 85% 45% "Please select one of the following installation options:"
Pop $0

${NSD_CreateRadioButton} 10 25u 40% 12u "&Server"
Pop $R0

${NSD_CreateRadioButton} 10 45u 40% 12u "&Client"
Pop $R1

${NSD_AddStyle} $R0 ${WS_GROUP}

${If} $R4 != ${BST_CHECKED}
${NSD_SetState} $R0 ${BST_CHECKED}
${Else}
${NSD_SetState} $R1 $R4
${EndIf}

${NSD_OnBack} OptionServerClientPageLeave

nsDialogs::Show

FunctionEnd


Function OptionServerClientPageLeave

${NSD_GetState} $R0 $R3
${NSD_GetState} $R1 $R4
MessageBox MB_OK "$$R0=$R3 -- $$R1=$R4"

FunctionEnd

Hi Red Wine,
It works very well with NSIS 2.37.
Thank you very much.

Jue