Archive: how to get value from droplist


how to get value from droplist
  Hi,
I'm creating install program and I've used droplist in ini file like this:
[Field 5]
Type=Droplist
;Flags=NOTIFY
State=COM1
ListItems=COM1|COM2|COM3|COM4|COM5
Left=180
Right=230
Top=10
Bottom=22

Everything works good, but I don't know how to read value, which is set by user.
Please help me.


Value is stroed in State, which must be read with MUI_INSTALLOPTIONS_READ (for Modern UI) or ReadINIStr (classic UI).

-Stu


A related question to Afrow UK: Is it OK to use ReadINIStr in Modern UI instead of using MUI_INSTALLOPTIONS_READ -- Would it cause any errors?


No.
These will do exactly the same thing:

ReadINIStr $R0 "$PLUGINSDIR\file.ini" "Field 1" "State"

!insertmacro MUI_INSTALLOPTIONS_READ $R0 "file.ini" "Field 1" "State"

Notice the only difference is that with MUI_INSTALLOPTIONS_READ you don't need to specify $PLUGINSDIR in the path.

-Stu


Thank you Afrow UK. My only concern is, I modify the .ini for the next page based on the selections in the current page, in which case, I believe a copy residing in $PLUGINSDIR\file.ini is what I want to write to -- Am I correct?


Yes. MUI_INSTALLOPTIONS_READ is what you can use.
You'd resort to using ReadINIStr with Classic UI or if your INI file isn't under $PLUGINSDIR.

-Stu


Thanks a lot


Hello Afrow,

i would really appreciate it if you can help with this problem.
i have the following ini file;

***91;Field 3***93;

>Type=Droplist
Flags=NOTIFY
State=1- Full Installation
ListItems=1- Full Installation|2- HMI Host|3- Database Host|4- Helmsman
Left=4
Right=-10
Top=22
Bottom=32

>***91;Field 4***93;
>Type=text
Left=0
Right=-1
Top=64
Bottom=-4
flags=MULTILINE|VSCROLL|READONLY
State="Description:\r\n\r\nFull Installation:\r\nThis type of installation will install the following:\r\n1 \
- MySQL Server 5.0\r\n2 - HPS_DB Database and IS3 Database\r\n3 - ISSS Suite including HMI and Helmsman\r\n4 \
- SevenCs Charts\r\nIt will also configure the system to Auto Admin Logon"
what i wish to do is that according to the option chosen by the user in the drop list, the state in field 4 should change automatically.
i tried the following, but nothing is happening...

ShowCustom


!insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)"

; Initialise the dialog but don't show it yet
InstallOptions::initDialog /NOUNLOAD "$PLUGINSDIR\testnotify.ini"
; In this mode InstallOptions returns the window handle so we can use it
Pop $0
; Now show the dialog and wait for it to finish
InstallOptions::show
; Finally fetch the InstallOptions status value (we don'
t care what it is though)
Pop $0
FunctionEnd

>Function LeaveCustom
ReadINIStr$0 "$PLUGINSDIR\testnotify.ini" "Settings" "State"

StrCmp $0 0 validate ; Next button?
StrCmp $0 3 comboBox ; Full install or DB
Abort; Return to the page

comboBox:
ReadINIStr $0 "$PLUGINSDIR\testnotify.ini" "Field 3" "State"
;messagebox mb_ok $0
strcmp$0 "1- Full Installation" 0 +6
WriteINIStr "$PLUGINSDIR\testnotify.ini" "Field 4" "State" "Description:\r\n\r\nFull Installation:\r\nThis type of installation will install the following:\r\n1 - MySQL Server 5.0\r\n2 \
- HPS_DB Database and IS3 Database\r\n3 - ISSS Suite including HMI and Helmsman\r\n4 - \
SevenCs Charts\r\nIt will also configure the system to Auto Admin Logon"
IfErrors 0 +2
messagebox mb_ok "Error writting to ini file"
messagebox mb_ok $0
abort
strcmp$0 "2- HMI Host" 0 +5
WriteINIStr "$PLUGINSDIR\testnotify.ini" "Field 4" "State" "Description:\r\n\r\nHMI Host:\r\nThis will install the HMI on this machine"
IfErrors 0 +2
messagebox mb_ok "Error writting to ini file"
abort
strcmp$0 "3- Database Host" 0 +5
WriteINIStr "$PLUGINSDIR\testnotify.ini" "Field 4" "State" "Description:\r\n\r\nDatabase Host:\r\nThis will install the following:\r\n1 - MySQL Server 5.0\r\n2 \
- HPS_DB Database and IS3 Database\r\n3 - ISSS Suite (Except HMI and Helmsman apps)\r\n4 \
- SevenCs Charts\r\nIt will also configure the system to Auto Admin Logon"
IfErrors 0 +2
messagebox mb_ok "Error writting to ini file"
abort
strcmp$0 "4- Helmsman" 0 +4
WriteINIStr "$PLUGINSDIR\testnotify.ini" "Field 4" "State" "Description:\r\n\r\nFull Installation:\r\nThis will install the Helmsman add"
IfErrors 0 +2
messagebox mb_ok "Error writting to ini file"
abort
validate:
>FunctionEnd
>

Hi Simon!

The ini file isn't read again by the installer. You have to send the text by sendmessage.

This macro is doing everything you need. Write the text to the ini file, in case you want to use back/next buttons and send it directly to the textbox.


;change text field and put value in ini file
!macro CHANGETEXTFIELD ELEMENT VALUE
!insertmacro MUI_INSTALLOPTIONS_WRITE ${VALUE} "my.ini" "${ELEMENT}" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $tmp "my.ini" "${ELEMENT}" "HWND"
SendMessage $tmp ${WM_SETTEXT} 0 "STR:${VALUE}"
!macroend


Cheers

Bruno

Originally posted by bholliger
Hi Simon!

The ini file isn't read again by the installer. You have to send the text by sendmessage.

This macro is doing everything you need. Write the text to the ini file, in case you want to use back/next buttons and send it directly to the textbox.


;change text field and put value in ini file
!macro CHANGETEXTFIELD ELEMENT VALUE
!insertmacro MUI_INSTALLOPTIONS_WRITE ${VALUE} "my.ini" "${ELEMENT}" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $tmp "my.ini" "${ELEMENT}" "HWND"
SendMessage $tmp ${WM_SETTEXT} 0 "STR:${VALUE}"
!macroend


Cheers

Bruno
Hello Bruno,
Thank you for ur quick responce.
while trying your macro, $tmp was returning an error, so i just changed it $1.

in function LeaveCustom (shown above)
i did the following,

!macro CHANGETEXTFIELD ELEMENT VALUE
!insertmacro MUI_INSTALLOPTIONS_WRITE "${VALUE}" "testnotify.ini" "${ELEMENT}" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $1 "$testnotify.ini" "${ELEMENT}" "HWND"
SendMessage $1 ${WM_SETTEXT} 0 "STR:${VALUE}"
!macroend

Function LeaveCustom
ReadINIStr $0 "$PLUGINSDIR\testnotify.ini" "Settings" "State"

StrCmp $0 0 validate ; Next button?
StrCmp $0 3 comboBox ; Full install or DB
Abort ; Return to the page

comboBox:
ReadINIStr $0 "$PLUGINSDIR\testnotify.ini" "Field 3" "State"
messagebox mb_ok $0
strcmp $0 "1- Full Installation" 0 +3
!insertmacro CHANGETEXTFIELD "Field 4" "Description:$\r$\n$\r$\nFull Installation:$\r$\nThis type of installation will install the following:$\r$\n1 \
- MySQL Server 5.0$\r$\n2 - HPS_DB Database and IS3 Database$\r$\n3 - ISSS Suite including HMI and Helmsman$\r$\n4 \
- SevenCs Charts$\r$\nIt will also configure the system to Auto Admin Logon"
abort
strcmp $0 "2- HMI Host" 0 +3
!insertmacro CHANGETEXTFIELD "Field 4" "Description:$\r$\n$\r$\nHMI Host:$\r$\nThis will install the HMI on this machine"
abort
strcmp $0 "3- Database Host" 0 +3
!insertmacro CHANGETEXTFIELD "Field 4" "Description:$\r$\n$\r$\nDatabase Host:$\r$\nThis will install the following:$\r$\n1 \
- MySQL Server 5.0$\r$\n2 - HPS_DB Database and IS3 Database$\r$\n3 \
-ISSS Suite (Except HMI and Helmsman apps)$\r$\n4 - SevenCs Charts$\r$\nIt will also configure the system to Auto Admin Logon"
abort
strcmp $0 "4- Helmsman" 0 +3
!insertmacro CHANGETEXTFIELD "Field 4" "Description:$\r$\n$\r$\nFull Installation:$\r$\nThis will install the Helmsman app"
abort

validate:

FunctionEnd


Now this has given me some weird behavior, it will only write to window for first option and not the rest.

thanx again :)

Hi Simon!

I think StrCmp in conjunction with relative jumps and macros is a bit difficult. Why don't you use the excellent flow control functions provided by logiclib?

Like ${Switch} ... ${Case} ... ${EndSwitch}? That might solve the problem.

Cheers

Bruno


Cheers Bruno,

your definitely the man, it worked perfectly with Logiclib. i was afraid this day will come where i have to fix my script to use LogicLib, and MUI insertmacro calls...

i only went along with Classic UI because more examples exist.

cheers mate,
Simon


Hi Simon!

Thanks for your feedback. Well, logiclib might be a bit confusing. But with time you'll see that it is convenient and easy to use. And the best of all it's a lot clearer than StrCmp ... +4.

Greetings from Sydney!

Cheers

Bruno