Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Is Variable Declared? (http://forums.winamp.com/showthread.php?t=233928)

MikeSchinkel 24th December 2005 05:21

Is Variable Declared?
 
Is there any way to determine in a script if a variable has been declared or not? I want to be able to declare a variable using a macro, but only if it hasn't already been declared.

Animaether 24th December 2005 06:13

Variables aren't so much declared as that they either contain data, or they don't. So you could just use :
StrCmp $Var "" +2 0
MessageBox MB_OK "Var is 'declared'"

Afrow UK 24th December 2005 08:27

Yes but if a variable hasn't been declared from within a macro, then that will throw a compiler warning.
You should define a constant of the same name of that variable and check if that constant exists with !ifdef.

E.g.
code:
!macro Var VarName
Var "${Var}"
!define "${Var}"
!macroend

!insertmacro Var MyVar

Function MyFunc
!ifdef MyVar
StrCpy $MyVar "blah"
!endif
FunctionEnd



-Stu

Animaether 24th December 2005 09:28

ah, good point!

dandaman32 25th December 2005 21:17

code:
!ifndef VAR_DECLARED
!define VAR_DECLARED
Var VAR_NAME
!endif



-dandaman32

MikeSchinkel 26th December 2005 08:02

Thanks for the suggestions. That's certainly a clever and viable workaround!

But not exactly what I was looking for as it pollutes the macro namespace and is more apt to cause collisions when using headers from multiple sources. :(

OTOH, I rearchitected what I was doing so I didn't end up needing it anyway. At least not this time. :)


All times are GMT. The time now is 04:56.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.