Archive: How to read the content of a variable?


How to read the content of a variable?
Hi.

I actually do not really understand what i'm coding, i think...

I want to get the path to reach the Common File directory... i'm using the following code to get it (i think this the right command at least):

ReadRegStr $9 HKLM Software\Microsoft\Windows\CurrentVersion, CommonFilesDir
then i just want to use the value stored in the variable named '$9'. Also i thought this could be done this way, but it seems i'm wrong...

!insertmacro UpgradeDLL $9\designer\MSDERUN.DLL "$9\designer\MSDERUN.DLL"
So my question is how can i read the value stored in variable $9 to use it anywhere in my script?

Really sorry for such idiot question but i can't find the answer in the documentation and anywhere in the forum... even if i got some tips but no more...

by the way i have to confess that the variable section is not treated well enough in the documentation to understand it well... but it's just my opinion anyway... cause' just need to put more effort in it??!!:cry:

Thanks

dave

You are mixing up compile-time and run-time. A variable can be used for run-time settings (like the destination of the DLL). Of course you can't use it for compile-time settings, like the location of the DLL on your system.


The sytax is not quite correct, the following should help:

Using NSIS 2.0b4

ReadRegDWORD $9 HKLM "Software\Microsoft\Windows\CurrentVersion" "CommonFilesDir"

!insertmacro UpgradeDLL "MSDERUN.DLL" "$9\designer\MSDERUN.DLL" "$SYSDIR"


$0-9 tend to be used as Global variable, ie: can be used in other sections/functions.
$R0-R9 tend to be used a temporary variable for the section/function.
To use $9 else where, just put it in the command you are using, for example:


StrCpy $1 "sheep" ;puts the word "sheep" into $1 variable

StrCpy $2 "3" ;puts the number "3" into $2 variable

DetailPrint "I have $3 $1" ;will display "I have 3 sheep" in details window


Alternatively you can use your own global or temporary variables, for example:


!define GV_Animal "sheep" ;puts the word "sheep" into global variable

Var "MyVariable ;Declare own variable
StrCpy "$MyVariable" "3" ;puts the number "3" into own variable

DetailPrint "I have $MyVariable ${GV_Animal}" ;will display "I have 3 sheep" in details window

The last example is not correct. Defined symbols are no variables, they will be replaced on compile time.


what a nice confusion we have... :rolleyes:


In the manual you can use !define to create a global value used by any part of the script, ie:


!define VERSION "V.1.0"
Name "Test Program ${VERSION}"

This code sets the name of the installer to "Test Program V.1.0"


At any point in the script you can retrieve it with ${Version}.

I thought it would only change if you did define at compile time?

Is there an alternative to setting a global value which can be used in the script at any point while compiling without the danager of it being replaced?

Or am I at the wrong end of the stick again? :)

No, you're right. Only the name is wrong:

!define GV_Animal "sheep" ;puts the word "sheep" into global variable

It's a defined symbol that will be replaced on compile-time. It's not a variable you can change.


I see what you mean now, sorry for not being clearer. :)

I have lots of code snippets I use for !includes and didn't relish the idea of having to through them and change the !defines.