Old 29th January 2016, 19:41   #1
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Reading value from Config file to textbox

Hi All,

I have a Custom Dialog that has a few ports that the user must enter. I have some default values in them. If there a config file existing in the install directory, the ports must auto populate on the custom dialog. I have all the pieces of the code in place. I just wanted to know if there is a cleaner way of doing it. I am pasting excerpts for just one of the port. Will need to duplicate this code for the other ports also.

1)In my main nsi I have this. $PortNumber is a global variable. I grab the value of the port.

IfFileExists $INSTDIR\conf\tomcat.properties 0 pastFilecheck
MessageBox MB_OK "found the properties file"
${ConfigRead} "$INSTDIR\conf\my.properties" "port.shutdown=" $R1
MessageBox MB_OK "Port number is: $R1"
StrCpy $PortNumber $R1
pastFilecheck:

2)In my custom dialog .nsh file I have this. Check if port value exists or load the default value.

${If} $PortNumber == ''
StrCpy $PortNumber '9954'
MessageBox MB_OK "New port number is :$PortNumber"
${NSD_SetText} $hCtl_FoundationDialog_TextBox1 $PortNumber

${EndIf}
; === TextBox1 (type: Text) ===
${NSD_CreateText} 127.7u 37.54u 111.24u 12.31u "$PortNumber"
Pop $hCtl_FoundationDialog_TextBox1
pkonduru is offline   Reply With Quote
Old 30th January 2016, 01:37   #2
demiller9
Senior Member
 
Join Date: Mar 2006
Location: Dallas
Posts: 462
It looks like you are trying to set the port number into the textbox before you have the textbox handle. Did you paste the code in the order it gets used?
demiller9 is offline   Reply With Quote
Old 1st February 2016, 19:20   #3
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Hi demiller9,

Yes, i pasted the code in the order it gets called. Basically the first part of the code is from a custom page leave function which comes before the actual page that has the port information. My code works fine, I only wanted to know if there is a cleaner way of doing this.

--Pavan
pkonduru is offline   Reply With Quote
Old 3rd February 2016, 20:01   #4
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
On the very first run, this line does nothing because the textbox handle is null:
Quote:
Originally Posted by pkonduru View Post

${NSD_SetText} $hCtl_FoundationDialog_TextBox1 $PortNumber

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 3rd February 2016, 23:32   #5
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
I set the $PortNumber to 9954 if its empty/null.
So, on the first run it does show 9954.
pkonduru is offline   Reply With Quote
Old 4th February 2016, 10:56   #6
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
That's weird, it shouldn't work but it does.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump