Page 1 of 1

Variable substituion in localization variables

Posted: Thu May 03, 2007 4:59 am
by Christoph Schneegans
Hi!

I am experiencing some strange problems with localization variables that contain variable references again. For example, my translations.German contains the line

Die Installation ist fehlgeschlagen: $LASTERROR$.

that is linked to a localization variable named "FinishMainText5", which is displayed in a dialog if necessary. However, in case of an error, only the text

Die Installation ist fehlgeschlagen: .

is displayed in the dialog although $LASTERROR$ is not empty as a MessageBox call confirms.

I have now changed the line in the translations.German file to

Die Installation ist fehlgeschlagen: $LastErrorLocalized$.

and call

Set Variable LastErrorLocalized to $LASTERROR$

right before the dialog is displayed. This works!

So my assumption is that there's a difference between pre-defined variables and user-defined variables. It seems that pre-defined variables in localization variables are resolved e.g. when the setup starts, while user-defined variables are not resolved until the localization variable is evaluated. Is this correct?

Posted: Thu May 03, 2007 5:13 pm
by MichaelNesmith
No, that kind of a distinction doesn't exist.

What is the timing of your calls like? Once Set Variable (or Set Localization Variable) is called, any existing variable references inside that call are resolved immediately. They are not kept unsubstituted for resolution at a later time.

So since $LASTERROR$='' (empty string) at start of setup, and since that's probably around when you are calling Set Variable, this is what ends up happening.

Posted: Fri May 04, 2007 4:53 am
by Christoph Schneegans
translations.German and project.mtx define these localization variables:

Code: Select all

LocVarStatic=Die Installation ist fehlgeschlagen: $LASTERROR$
LocVarDynamic=Die Installation ist fehlgeschlagen: $LastErrorDynamic$
And this is the script:

Code: Select all

Set Localization Variable LocVarStatic to 
Set Localization Variable LocVarDynamic to 
 
Set Variable LASTERROR to foobar
Set Variable LastErrorDynamic to $LASTERROR$
MessageBox: , $LocVarStatic$ // Displays "Die Installation ist fehlgeschlagen:"
MessageBox: , $LocVarDynamic$ // Displays "Die Installation ist fehlgeschlagen: foobar"
 
Set Variable LASTERROR to foobar2
Set Variable LastErrorDynamic to $LASTERROR$ 
MessageBox: , $LocVarStatic$ // Displays "Die Installation ist fehlgeschlagen:"
MessageBox: , $LocVarDynamic$ // Displays "Die Installation ist fehlgeschlagen: foobar2"

Terminate Installation
So the reason why LocVarDynamic is evaluted every time is that the LastErrorDynamic is declared after LocVarDynamic?

Posted: Fri May 04, 2007 7:52 am
by MichaelNesmith
Exactly. If VARIABLE hasn't been defined as a variable, then $VARIABLE$ is interpreted just as a string literal.