Archive: Text Box


Text Box
I have searched the forums for this but have not found something that works. I have a custom page that has a text box in it, Field 4. I want to read from the user's registry and insert a value into this text box. The reading from the registry appears to be working but the writing to the text box appears not to be working. I have tried the following:

ReadRegStr $DatabaseServer HKLM "SOFTWARE\test" "TestServer"

!insertmacro MUI_INSTALLOPTIONS_WRITE "DatabaseLogin.ini" "Field 4" "State" $DatabaseServer

----

ReadRegStr $DatabaseServer HKLM "SOFTWARE\test" "TestServer"

!insertmacro MUI_INSTALLOPTIONS_WRITE "DatabaseLogin.ini" "Field 4" "Text" $DatabaseServer

---

ReadRegStr $DatabaseServer HKLM "SOFTWARE\test" "TestServer"

!insertmacro MUI_INSTALLOPTIONS_WRITE "DatabaseLogin.ini" "Field 4" "State" $DatabaseServer

----

WriteINIStr '$PLUGINSDIR\DatabaseLogin.ini' "Field 4" "State" $DatabaseServer


I think it may have to do with where I'm placing it I do not know for sure. I've tried before and after this section of code:

!insertmacro MUI_INSTALLOPTIONS_EXTRACT "DatabaseLogin.ini"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "DatabaseLogin.ini"

in my Form show area. Please let me know if you need more information or if you can help.
Thank you!


are you writing this to the ini-file before displaying the page?


I don't know 100% what you mean. I have done it before and after I call the function for the page and before and after this line and it has made no difference. Can you maybe clarify more?

!insertmacro MUI_INSTALLOPTIONS_DISPLAY "DatabaseLogin.ini"


Just 3 steps:
1st extract the INI
2nd modify it
3rd display it


Right after the extract I tried setting the value and it still did not work. I have no clue what I'm doing wrong. When I go to the page that should have the value change it still says the default value. Here is what I tried:

!insertmacro MUI_INSTALLOPTIONS_EXTRACT "DatabaseLogin.ini"

!insertmacro MUI_INSTALLOPTIONS_WRITE "DatabaseLogin.ini" "Field 4" "State" "Hello"

WriteINIStr '$PLUGINSDIR\DatabaseLogin.ini' "Field 4" "State" "test"

WriteINIStr '$PLUGINSDIR\DatabaseLogin.ini' "Field 4" "Text" "test2"

None of the values were in the text box as I would have expected. Just 127.0.0.1 was in the text box which is the default value that I set when creating the text box on the page.

Thank you! Sorry I'm having such a hard time with this.


outfile test.exe
showinstdetails show

!include winmessages.nsh

Page license
Page custom CreateCustom
page Instfiles

Function CreateCustom
InitPluginsDir
WriteINIStr "$PLUGINSDIR\Cust.ini" "Settings" "NumFields" "1"
WriteINIStr "$PLUGINSDIR\Cust.ini" "Field 1" "Type" "Text"
WriteINIStr "$PLUGINSDIR\Cust.ini" "Field 1" "Top" "59"
WriteINIStr "$PLUGINSDIR\Cust.ini" "Field 1" "Bottom" "-59"
WriteINIStr "$PLUGINSDIR\Cust.ini" "Field 1" "Left" "20"
WriteINIStr "$PLUGINSDIR\Cust.ini" "Field 1" "Right" "-20"
WriteINIStr "$PLUGINSDIR\Cust.ini" "Field 1" "State" "Hello, I am a text field."

push $0
InstallOptions::InitDialog /NOUNLOAD "$PLUGINSDIR\Cust.ini"
ReadRegStr $R0 HKLM "SOFTWARE\NSIS" ""
messagebox mb_ok "$R0"
ReadINIStr $R1 "$PLUGINSDIR\Cust.ini" "Field 1" "hwnd"
SendMessage $R1 ${WM_SETTEXT} 0 "STR:$R0"

pop $0
InstallOptions::Show "$PLUGINSDIR\Cust.ini"
pop $0
pop $0
FunctionEnd


section

sectionend

In order for this to work, do I have to create the INI file in the fly like you did? I think my issue is that I have created the ini file in a separate file already with a GUI editor in Eclipse, and I'm calling and using that.


Here is what I have maybe this will help.

My DatabaseLogin.ini file


[Settings]
NumFields=7

[Field 1]
Type=Label
Left=41
Top=49
Right=101
Bottom=58
Text=Database Server:

[Field 2]
Type=Label
Left=41
Top=66
Right=112
Bottom=75
Text=Database Username:

[Field 3]
Type=Label
Left=41
Top=84
Right=112
Bottom=94
Text=Database Password:

[Field 4]
Type=Text
Left=120
Top=46
Right=252
Bottom=59
State=127.0.0.1

[Field 5]
Type=Text
Left=120
Top=64
Right=252
Bottom=77
State=sa

[Field 7]
Type=Label
Left=41
Top=15
Right=228
Bottom=38
Text=Please enter your database connection information below.
[Field 6]
Type=Password
Left=120
Top=82
Right=252
Bottom=95


Installer Code - I kind of chopped it up a little so some basic stuff may be missing.

ReserveFile "DatabaseLogin.ini"

!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

; The name of the installer
Name "Installer"

; The file to write
OutFile "setup.exe"

; The default installation directory
InstallDir "C:\Installer"

;Uninstall mode
!insertmacro UNATTENDED_UNINSTALL

; Pages
!insertmacro MUI_PAGE_WELCOME
Page custom SQLLoginInfoShow SQLLoginInfoLeave
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

;Page components

## Languages
!insertmacro MUI_LANGUAGE "English"

; Variables
var InstallSQL
var DatabaseServer
var DatabaseUsername
var DatabasePassword
var Upgrade

UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------

Function .onInit
Call CheckIISVersion
FunctionEnd

Function SQLLoginInfoShow
${if} $InstallSQL == 1
Abort
${Endif}

WriteINIStr '$PLUGINSDIR\DatabaseLogin.ini' "Field 4" "State" "blah"

!insertmacro MUI_HEADER_TEXT "Database Login Information" "Please enter your database login inforation below."
;ReserveFile "DatabaseLogin.ini"

!insertmacro MUI_INSTALLOPTIONS_EXTRACT "DatabaseLogin.ini"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "DatabaseLogin.ini"


FunctionEnd

Function SQLLoginInfoLeave
readinistr $DatabaseServer '$PLUGINSDIR\DatabaseLogin.ini' 'Field 4' 'State'
readinistr $DatabaseUsername '$PLUGINSDIR\DatabaseLogin.ini' 'Field 5' 'State'
readinistr $DatabasePassword '$PLUGINSDIR\DatabaseLogin.ini' 'Field 6' 'State'
;check to make sure they can login to the db provided
MSSQL_OLEDB::SQL_Logon /NOUNLOAD "$DatabaseServer" "$DatabaseUsername" "$DatabasePassword"
pop $0
${if} $0 == 1
;Error connecting to SQL Database
pop $0
MSSQL_OLEDB::SQL_GetError /NOUNLOAD
Pop $0
Pop $0
MessageBox MB_OK $0
Abort
${Endif}

FunctionEnd


Of course there's no need to create the INI on the fly, I did so just for convenience.
Taking a look at your code,
remove the line !insertmacro MUI_INSTALLOPTIONS_EXTRACT "DatabaseLogin.ini" and add it into function .onInit.


Awesome! that was it. Thank you and sorry I was difficult :)