Tutorial: Using labels in macro's: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
m (Updated author and download links, and changed format of some pages.)
Line 23: Line 23:
-Stu
-Stu


Page author: Afrow UK
Page author: [[User:Afrow UK|Afrow UK]]

Revision as of 12:45, 23 April 2005

Description

Labels work fine in macro's until you start to insert the macro's more than once in the same Section or Function!

Solution

The work-around for this problem is quite simple...

## Our macro
!macro DoSomething Param
 !define UniqueID ${__LINE__}
 
 StrCmp ${Param} "something" 0 NoSomething_${UniqueID}
  ...
 NoSomething_${UniqueID}:
 
 !undef UniqueID
!macroend

What we do is create a unique identity (${UniqueID}) for each instance of !insertmacro and place this unique identity in each label reference. This ensures that all label groups are unique no matter how many times we use !insertmacro.

We use ${__LINE__} (current line number) for the UniqueID as it will always change between each !define. We have to !undef-ine UniqueID at the end of the macro too, so the next !insertmacro can re-define a new line number to UniqueID.

-Stu

Page author: Afrow UK