[英]NSI script : calling one macro from another using insertmacro gives error
我試圖在NSI腳本中從另一個調用1宏。 兩個宏都有MB_OKCANCEL。 編譯時會出現以下錯誤:
** [exec]錯誤:函數“”中已聲明標簽“ abort_inst:”
!include "MUI2.nsh"
OutFile abc.exe
!macro installA
MessageBox MB_OKCANCEL "A?" IDOK lblinstall IDCANCEL abort_inst
abort_inst:
ABORT
GoTo lblinstall
lblinstall:
!macroend
!macro uninstallA
MessageBox MB_OKCANCEL "?" IDOK install_A IDCANCEL abort_uninstall
abort_uninstall:
ABORT
install_A:
!insertmacro installA
!macroend
Function .onInit
ReadRegStr $0 HKLM "x" "version"
${If} $0 == ""
!insertmacro installA
${Else}
!insertmacro uninstallA
${EndIf}
FunctionEnd
Section "required" main_section
SectionEnd
請幫忙
(下一次,請確保您的代碼沒有奇怪的換行符)
插入宏時, !macro
和!macroend
之間的所有代碼!macroend
將替換您的!insertmacro
。 因此,您不應該在宏中使用靜態標簽-您只能插入一次宏(使宏無意義!)。可以使用相對跳轉(例如Goto +2
),也可以通過向標簽添加參數來使標簽動態化,例如:
!macro myMacro param1
${param1}_loop:
MessageBox MB_YESNO "Loop this message?" IDYES ${param1}_loop
# some more code
${param1}_end:
!macroend
但是,由於您沒有將任何參數傳遞給宏,所以為什么不簡單地使用函數呢?
Function installA
# your code here
Function
Function uninstallA
# your code here
Call installA
FunctionEnd
通過將一個宏轉換為Function可以解決此問題,如@idelberg所建議
同樣,只要使用宏,就不能使用靜態標簽。 靜態標簽只能在功能或部分中使用一次。 您對宏的使用將轉換為以下內容:
Function .onInit
ReadRegStr $0 HKLM "x" "version"
${If} $0 == ""
MessageBox MB_OKCANCEL "A?" IDOK lblinstall IDCANCEL abort_inst
abort_inst:
Abort
Goto lblinstall
lblinstall: # FIRST TIME USE
${Else}
MessageBox MB_OKCANCEL "?" IDOK install_A IDCANCEL abort_uninstall
abort_uninstall:
Abort
install_A:
MessageBox MB_OKCANCEL "A?" IDOK lblinstall IDCANCEL abort_inst
abort_inst:
Abort
Goto lblinstall
lblinstall: # SECOND TIME USE
${EndIf}
FunctionEnd
因此,由於lblinstall
標簽被使用了兩次,因此無法使用。 相反,您可以執行以下操作:
Function installA
MessageBox MB_OKCANCEL "A?" IDOK lblinstall
Abort
lblinstall:
FunctionEnd
Function uninstallA
MessageBox MB_OKCANCEL "?" IDOK install_A
Abort
install_A:
Call installA
FunctionEnd
Function .onInit
ReadRegStr $0 HKLM "x" "version"
${If} $0 == ""
Call installA
${Else}
Call uninstallA
${EndIf}
FunctionEnd
(我還可以自由地從您的示例中刪除一些不必要的標簽)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.