Archive: Constants (newbie)


Constants (newbie)
just another silly question,
is there any difference writting a constant like this "${INSTDIR}" and "$INSTDIR"

Yehia


$INSTDIR is a run-time variable that contains the installation folder, it can be modified while your installer is running.

${BLA} is a compile-time define, it will be replaced by the value you have defined by the compiler (it does not change the actual installer, only makes scripting easier).


this means that $bla is an already defined constant and the ${bla} is a user defined constant


No, $INSTDIR is NOT an onstant. It's a variable, it will be changed during the execution of the installer. You can also define your own variables (like $BLA).

${SOMETHING} is a compile-time defined symbol. When you compile your script, it will be replaced by the defined value. Example:

!define SOMETHING "my text"
MessageBox MB_OK "${SOMETHING}"

${SOMETHING} will be replaced by the compiler, you will get:

MessageBox MB_OK "my text"


and what if wrote:
!define SOMETHING "my text"
MessageBox MB_OK "$SOMETHING"
?


If you did this...
!define SOMETHING "my text"
Section
MessageBox MB_OK "$SOMETHING"
SectionEnd
The MessageBox would simply display "$SOMETHING" and not "my text".
You would probably also get a compile error saying "Unknown variable $SOMETHING, ignored" or similar, because $SOMETHING has not been set using Var.

This would work...
!define SOMETHING "my text"
Section
MessageBox MB_OK "${SOMETHING}"
SectionEnd

So would this...
Var SOMETHING
Section
StrCpy $SOMETHING "my text"
MessageBox MB_OK "$SOMETHING"
SectionEnd

And so would this...
!define SOMETHING $9
Section
StrCpy ${SOMETHING} "my text"
MessageBox MB_OK "${SOMETHING}"
SectionEnd
Here ${SOMETHING} is set as a NSIS variable for its constant, which means that it is variable (changeable during run-time).

The difference is that with !define SOMETHING "my text" you will not be able to modify the contents of ${SOMETHING} whereas with $SOMETHING, you can.

Variable obviously means it can change variably.
Constant obviously means it cannot change, and stays the same constantly.

From the descriptions above, you can recognise the difference easily, even if you have none or little programming knowledge.

-Stu


thanks a lot people,
this nsis is great, i was using wise and turned to nsis just today,
the old size was 210kb, now it's 69kb only!!!!!1