Archive: Section Name question in 2.16


Section Name question in 2.16
Hello,
I'm having a problem with titles of sections. I assign
variables within page create functions, and the values do
not seem to propogate to section titles. Maybe a code snippet will help. (Here is my problem, at the simplest level, in a contrived code example)


; The name of the installer
Name "Delete File"

; The file to write
OutFile "delfile.exe"

; The default installation directory
InstallDir $PROGRAMFILES\DeleteFile

Var file
Var result
;--------------------------------

; Pages
Page custom LoadFile Empty "File"
Page directory
Page components
Page instfiles

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

Function .onInit
InitPluginsDir
File /oname=$PLUGINSDIR\file_path.ini "file_path.ini"
;; set an initial value
StrCpy $file "initial value"
FunctionEnd

Function LoadFile
InstallOptions::dialog "$PLUGINSDIR\file_path.ini"
;; It puts the status on the stack
Pop $result
ReadINIStr $file "$PLUGINSDIR\file_path.ini" "Field 1" "State"
FunctionEnd

Function Empty
;; no validation
FunctionEnd

; The stuff to install
Section "Delete File $file"
MessageBox MB_OK "File = $file"
Delete $file
SectionEnd ; end the section



What happens here is that I popup a request for a file to choose to delete, and when I choose that file, the section page still says "Delete file initial value" as the section title, even though the MessageBox says "File = <whatever file I chose>". It appears to me as though the strings that are used to populate the Section page must be parsed before the page functions get called.

What is strange is that when I compile and run the exact same code in v2.0rc4, I get the behaviour that the Section Title is correct, it actually says "Delete File <file I chose>".

Does anyone know why this is the case?

-Evan


This code in LoadFile:

ReadINIStr $file "$PLUGINSDIR\file_path.ini" "Field 1" "State"
should be in the 'empty' function. Installoptions writes the value to the ini file after you click next, but before the 'empty' function is executed. You read from the ini file in the leave function (in this case the function is called 'empty').

You are also confusing compile-time with run-time. Defines are used at compile time and look like this: ${HELLO}. Variables are used at run-time and look like this: $HELLO.
You can use compile-time defines at run-time, but not the other way around eg. you can't use run-time variables at compile-time.

Section is a compile-time command, and the title you give it at compile-time is actually saying 'Delete file ', because $file is not used at compile-time, it is used at run-time, and therefore has the value "" (null string). Use SectionSetText to change the text at run-time.

Also, a custom page appends the text to the caption at run-time so I have removed "file" from the end of the page command.

Here is the code that changes the section name at runtime.

; The name of the installer
Name "Delete File"

; The file to write
OutFile "delfile.exe"

; The default installation directory
InstallDir $PROGRAMFILES\DeleteFile

Var file

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

; Pages
Page custom LoadFile Empty
Page directory
Page components
Page instfiles

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

Function .onInit
InitPluginsDir
File /oname=$PLUGINSDIR\file_path.ini "file_path.ini"
;; set an initial value
StrCpy $file "initial value"
FunctionEnd

Function LoadFile
InstallOptions::dialog "$PLUGINSDIR\file_path.ini"
;; It puts the status on the stack
Pop $0 ;$0 to $9 and $R0 to $R9 are internal variables for you to use.
FunctionEnd

Function Empty
ReadINIStr $file "$PLUGINSDIR\file_path.ini" "Field 1" "State"
; Set the section text.
SectionSetText Sec_Index "Delete file $file"
FunctionEnd

; The stuff to install
Section "Dummy" Sec_Index ;name will be changed at run-time
MessageBox MB_OK "File = $file"
Delete $file
SectionEnd ; end the section

I thank you for your reply, though there is one thing I find strange. When I compile and run this script, the section name is not "Delete file:, it is "Delete file initial value", so the Section Name is not completely determined at compile time, as the .onInit function has been called. However, the PageLeave function has not yet been called. This is why I thought the behavior was strange. When I used v2.0RC4, the Section title was "Delete File: C:\file.txt" or whatever I chose. Has the time that the section listing page gets populated within the workflow changed between the versions?


Never read from the INI file in the same function that displays the InstallOptions dialog (i.e. the Show function). InstallOptions writes changes to the INI file after leaving the page (i.e. the Leave function) and not before.

Your other problem which Jason has made is that you need to move your Empty function below your Sections, because otherwise the constant Sec_Index has yet to be defined when used where it is now in your script.

Finally, the SectionSetText Sec_Index ... needs to be:
SectionSetText ${Sec_Index} ...
Otherwise you are trying to set the text of a Section with an index number that is "Sec_Index". You could probably tell that that is a string value and not an integer value. ${Sec_Index} is a defined compile time constant that will contain the Section index.

-Stu


Thanks for pointing that out, Afrow UK. I never knew that if you had to change the section on run-time, the function had to be below the sections. I also momentarily forgot to put ${} around it.


Section "my section" MySec
Is identical to doing:
!define MySec 0

Naturally, if you try to use the MySec constant before it is defined, you will get a compiler warning.

-Stu