Forum Discussion

scrier's avatar
scrier
Contributor
14 years ago

Assign alias to variables.

Is there some way to assign Aliases to global variables in scripting so that you can update them in one file when the Aliases is changed between software revisions. This can change if they cleanup the namegiving between releases for example and it's quite annoying to change in each script file that uses the Alias.



Compare

Regions.Compare("lbl_NavigationTest", Aliases.application.wndQwidget.QWidget.Statusrow.frmMain.framebox_2.lbl_navigationPath)



with

var lblNavigationInfo = Aliases.application.wndQwidget.QWidget.Statusrow.frmMain.framebox_2.lbl_navigationPath;

Regions.Compare("lbl_NavigationTest", lblNavigaionInfo)



I wan't to do the latter but with global alias variables so that if Aliases.application.wndQwidget.QWidget.Statusrow.frmMain.framebox_2.lbl_navigationPath changes to Aliases.application.wndQwidget.QWidget.Statusrow.frmMain.fmrInfo.lbl_navigationPath I can do this in one place instead of each region compare that uses the Alias.

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Community Hero
    Hi Andreas,



    While technically it is possible to do what you are asking for, the better approach is to assign textual representation of the alias to some public variable (defined as per your scripting language requirements) and use this variable where needed using eval/evaluate function (again, as per your scripting language) to resolve the text to actual object.

    E.g. something like that (pseudo-language, untested):

    var lblNavigationInfo = "Aliases.application.wndQwidget.QWidget.Statusrow.frmMain.framebox_2.lbl_navigationPath";

    ...

    if (eval(lblNavigationInfo + ".Exists"))

      Regions.Compare("lbl_NavigationTest", lblNavigaionInfo);

    else

      Log.Warning(lblNavigationInfo + " was not found");



    However, the beauty of aliasing is that you can define the tree of aliases as per your needs (see relevant help topic for how to organize the tree of aliases) and then, with properly defined NameMapping (i.e. with the use of Extended Find, Conditional NameMapping and Configurations (again, see the relevant help topics for mode details)) you will not need to edit the tree of aliases when the nameMapping scheme changes, but only to adjust the nameMapping tree leaving Aliases as they are.
  • Is it possible to define smaller Aliases thatn the current searchpaths?



    i.e. 



    var AliasNavigationInfo = Aliases.application.wndQwidget.QWidget.Statusrow.frmMain.framebox_2.lbl_navigationPath;



    I wan't to shorten the Alias name as much as possible and still be ale to use it. We have soo long paths to all and it's annoying if they change.
  • Hi,



    Just drag 'lbl_navigationPath' in Name Mapping editor to any tree level you need. The Aliases tree is logical, you can create a custom structure there.
  • AlexKaras's avatar
    AlexKaras
    Community Hero
    A typo in my pseudo-code:

    instead of

    Regions.Compare("lbl_NavigationTest", lblNavigaionInfo);

    it must be

    Regions.Compare("lbl_NavigationTest", eval(lblNavigaionInfo));