Page 1 of 1

(Pre-) Definition of Variables

Posted: Fri Nov 06, 2015 2:18 pm
by InstallAware@Jelich.info
Hi Support Team,

Am I right in my assumption that
- any action providing a combo box for the variable (e.g. Check For Process) does not require the variable to be defined in advance (Set Variable)
- any action with only an edit field for the variable (e.g. Call DLL Function) requires the variable to be defined earlier in the script?

Or is the key difference Build-In Command vs. Plug-In Command?

Best regards
Michael

Re: (Pre-) Definition of Variables

Posted: Mon Nov 09, 2015 7:56 am
by FrancescoT
Dear Michael,

it's Always required to declare "CUSTOM" variables before to use them.

Regards

Re: (Pre-) Definition of Variables

Posted: Tue Nov 10, 2015 1:35 pm
by InstallAware@Jelich.info
Dear Francesco,

I do not agree with you. Please try the following:

Read Registry Key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CommonFilesDir into GUCKSTDU
MessageBox: Huhu, $GUCKSTDU$


{MSI Script:
~InstallAware Clipboard Data~
~MessageBox~
~{4EDD1630-D9DB-41E9-A0AC-0BFE26F00C7D}~
~Huhu~
~$GUCKSTDU$~
~0~
~1~
~~
~Read Registry~
~{2922F9C7-CDD5-4F33-9410-58D70A5F9B26}~
~GUCKSTDU~
~2~
~SOFTWARE\Microsoft\Windows\CurrentVersion~
~CommonFilesDir~
}

This works fine without any error. I'm pretty sure that GUCKSTDU is not a predefined variable and thus considered a custom variable. It is NOT declared in the Compiler Variables section or anywhere else before use.

I also discovered during PlugIn development that I can add variables to the 'Variables' argument of function 'RunTimeExecute' without any error - the added variable and its value is accessible (and correct) in my Native Setup MSI Script. Therefore using undeclared variables is also successful using my PlugIn's.

I have not very often an error message claiming the usage of undefined variables (but I remember that I've had some... - but I cannot remember the commands/actions raising the error).

Does the script above raise an error in your IA IDE?

Best regards
Michael

Re: (Pre-) Definition of Variables

Posted: Tue Nov 10, 2015 1:58 pm
by FrancescoT
Dear Michael,

it Always a good and recommended practice to DECLARE CUSTOM VARIABLES before to use them ... you may have un-expected results and especially when passing values to a plugin.

I full understand what you are trying to prove and under some circumstances it may work ... but believe me, I highly recommend you to declare them.

Regards

Re: (Pre-) Definition of Variables

Posted: Tue Nov 10, 2015 2:29 pm
by bokkie
InstallAware@Jelich.info wrote:Dear Francesco,

I do not agree with you. Please try the following:

Read Registry Key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CommonFilesDir into GUCKSTDU
MessageBox: Huhu, $GUCKSTDU$



Michael,

Don't ignore Francesco's advice about declaring your variables before you use them. I would say 99.9% of the time you will get away with it if you don't declare them. Most statements and plugins will be kind to you. Don't push your luck because one day an undeclared variable just might turn around and bite you. I've never had a problem with my own plugins but I always make sure I declare my variables at the top of the script and give them default values where possible.

Re: (Pre-) Definition of Variables

Posted: Tue Nov 10, 2015 3:23 pm
by InstallAware@Jelich.info
Peter and Francesco,

I assumed that pre-definition was a 'relict' from earlier versions because I very often see undeclared variables used (e.g. SELECTED, SUCCESS,...)

Thank you for your advice. I'll consider your recommendation. Should not be difficult ;-)

But if it is of that importance, what do you think about a check during compile? (like 'OPTION EXPLICIT' in other 'languages'?) In case undeclared variables are used compile should fail or at least generate a warning...

Best regards
Michael

Re: (Pre-) Definition of Variables

Posted: Wed Nov 11, 2015 9:47 am
by bokkie
I like that idea of an OPTION EXPLICIT concept. It would certainly be useful. I'd envisage it being implemented as an IDE setting. I will ask someone who knows someone at InstallAware who might be able to punt it for consideration.

Francesco? Are you there? :D

Re: (Pre-) Definition of Variables

Posted: Wed Nov 11, 2015 12:53 pm
by FrancescoT
I am having a beer on a lost beach of a unreachable country ...bip ...bip... can you hear me? 8)

Let me check your request!

Regards

Re: (Pre-) Definition of Variables

Posted: Thu Nov 19, 2015 12:04 pm
by FrancescoT
Dear Michael and Peter,

I am sorry ... but I believe it'll be very very difficult to implement a sort of OPTION EXPLICIT.

In reality the compiler already checks variables declaration, but this is limited to those used with internal IA commands or statements.
Unfortunately this is not possible when a script entry refers to a plugin statement or similar.
In this circumstances the compiler cannot verify if a variable has been used with a specific "script line". This due the fact that the compiler ignores the logic that stays behind a plugin entry ... and this cannot be different ... unless the plugin doesn't implement a specific "build time method" at such purpose ... but this becomes to be a complicated thing.

Regards