Skip to content
⌘ NSIS Forum Archive

${__SECTION__} is not defined if section is hidden "-"

10 posts

dbach#

${__SECTION__} is not defined if section is hidden "-"

Hi forum users,

this seems like a bug to me. When I hide a section like this ...

Section "-I am not shown" HIDDENSEC
SectionEnd

the define/var ${__SECTION__} will not be set. This is a bug, right? If not how to get the sectionname?

Kind regards,
dbach
MSG#
Hidden sections are nameless, even if you give them a name. I filed a report about this issue ages ago, but it hasn't been fixed yet...
Animaether#
I don't think they're nameless - they're just textless. This can almost be explained by ways of the SectionSetText function, which details that setting a section's text to "" (an empty string) will hide it.

So when you specify...


Section "-I am not shown" HIDDENSEC
SectionEnd
You're doing little more than making it easier for yourself, while browsing your source file, to identify sections. The section ID will still be stored in ${HIDDENSEC}, though. So you can do something like this...


!include "MUI2.nsh"

OutFile "test.exe"

setCompress off

!define MUI_PAGE_CUSTOMFUNCTION_PRE Pre
!insertmacro MUI_PAGE_COMPONENTS

Section "I am not shown" HIDDENSEC
SectionEnd

Function Pre
SectionGetText ${HIDDENSEC} $0
MessageBox MB_OK "[$0]"
SectionSetText ${HIDDENSEC} ""
FunctionEnd

!insertmacro MUI_LANGUAGE "English"
Which will pop up the section's text, and then hide it on run-time. Not sure what the point of that (getting the section text of a section that's going to be hidden) would be, though - but if you have a use for it.. go for it.
dbach#
I want to use something like this:

Var _day
Var _month
Var _year
Var _dayname
Var _hour
Var _minute
Var _second
!define SECTIONINFO '!insertmacro SECTIONINFO'
!macro SECTIONINFO
    ${GetTime} "" "L" $_day $_month $_year $_dayname $_hour $_minute $_second ; $0=DD, $1=MM, $2=YYYY, $3=dayname, $4=hh, $5=mm, $6=ss
    ClearErrors
    LogText ""
    LogText "------------------------------------------------------------------------------"
    LogText "${__SECTION__}"
    LogText "($_day.$_month.$_year $_hour:$_minute:$_second)"
    Logtext "------------------------------------------------------------------------------"
!macroend
Section "I am visible" VISIBLESEC
   ${SECTIONINFO}
SectionEnd
Section "-I am hidden" HIDDENSEC
   ${SECTIONINFO}
SectionEnd 
The first works, the second not. Is there a simple workaround so that I can contine use my macro without defining a pre?
Animaether#
no super-simple transparent work-around that I can think of.

With the Pre function you have to remember to make the appropriate sections invisible - that's some manual editing and tracking.

One alternative would be to add a parameter to your SECTIONINFO macro and supply the information yourself, a la:
!macro SECTIONINFO SectionText
...
  LogText "${SectionText}"
...
!macroend
...
Section "I am visible" VISIBLESEC
   ${SECTIONINFO} "I am visible"
SectionEnd 
Section "" HIDDENSEC ; Section text not strictly needed here
  ${SECTIONINFO} "I am hidden"
SectionEnd 
But then you have to adjust all of your SECTIONINFO invokes.
Afrow UK#
You could in addition only use __SECTION__ if it is defined:
!ifdef __SECTION__
LogText "${__SECTION__}"
!else
LogText "${MacroParam}"
!endif
Save you repeating section names twice.

Stu
dbach#
Originally Posted by Afrow UK View Post
You could in addition only use __SECTION__ if it is defined:
!ifdef __SECTION__
LogText "${__SECTION__}"
!else
LogText "${MacroParam}"
!endif
Save you repeating section names twice.

Stu
Its doesn't work that way bcs. __SECTION__ is defined but empty. This works:
${If} "${__SECTION__}" != ""
LogText "${__SECTION__}"
${Else}
LogText "${MacroParam}"
${EndIf}
Animaether#edited
wouldn't you still have to specify -something-, even if an empty string, for the macro, though?

e.g.
!include "MUI2.nsh"
OutFile "test.exe"
!macro SECTIONINFO SectionText
  MessageBox MB_OK "${SectionText}"
!macroend
!define SECTIONINFO `!insertmacro SECTIONINFO`
Section "I am not shown" HIDDENSEC
    ${SECTIONINFO}
SectionEnd
!insertmacro MUI_LANGUAGE "English" 
fails with: !insertmacro: macro "SECTIONINFO" requires 1 parameter(s), passed 0!
Afrow UK#
Yes of course.

Edit: dbach you could instead do:
!if `${__SECTION__}` != ``
LogText "${__SECTION__}"
!else
LogText "${MacroParam}"
!endif
Stu