amithsid
11 years agoContributor
TC is accessing public variables across scripts
Hello,
I have many units in the same folder under a script of a project. Inside a folder, many units have to access the public variables declared in that particular unit.
The problem is when I run a script; TC tries to search for another public variable declared in a different script under the same folder, what is the solution?
Thank you,
Amith n g
I have many units in the same folder under a script of a project. Inside a folder, many units have to access the public variables declared in that particular unit.
The problem is when I run a script; TC tries to search for another public variable declared in a different script under the same folder, what is the solution?
Thank you,
Amith n g
- Hi amith, when using multiple Script Units that may have name clashes, I would recommend using the fully qualified name, i,e, <ScriptUnit>.<MemberName>, as described in the Using Methods and Variables Defined in Another Unit documentation:
"Once an external unit is linked to the current one, all the routines, as well as global variables and constants of the external unit, can be called in the current unit. It is recommended, though not obligatory, to prefix the names of external routines, variables and constants with the unit's name. That is, in general, any of the following code instructions is correct:
MyExtUnit.MyRoutine(Param1, Param2)
MyRoutine(Param1, Param2)
MyExtUnit.MyVariable
MyVariable
MyExtUnit.MyConstant
MyConstant
However, you must specify the name of the referenced unit in the following cases:
When the current unit already contains a routine, global variable or global constant with the same name. Without prefixing, the routine, variable or constant of the current unit will be called.
When the name of an external routine is the same as the name of an external unit. Calling such a routine without a prefix will cause an exception.
For VBScript and DelphiScript: when calling routines, variables or constants declared in a third unit."
In fact, our coding standard is that any member that is called from another Script Unit, regardless of a clash existing or not, will ALWAYS be called using the fully qualified name
Regards,
Phil Baird