Forum Discussion

ngocvo3103_1's avatar
ngocvo3103_1
Occasional Contributor
14 years ago

Is there a shorter way to refer to a control?

Hi all,



When we call a control to work, we have to call from the parent control to the childs, sometimes, there are alot of childs to call. To make it shorter and easier to call a control, I try to assign all the controls to variables. But this only works correctly when I put the assign lines inside the current function. If I put these line outside the function, I can still use the variables inside the function, but when I put a dot "." to see what action can I use with this control, nothing shows up. Is there anything I can do to make it work correctly in this case? Please have a look in the attached pictures for more detail.



Thanks,

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The method not showing up in your first example does not mean that the method cannot be used.



    The difference is in how the script is interpreted by the parser.  Because the variables are declared outside of a function, they are not resolved unit run time so they don't show up in Code Completion.  If the variable is referenced inside the function, they resolve in the parser and you can access them.



    A better way of doing this, though, might by to use Aliases to shorten your calls.  If done properly, you could simply have



    Aliases.MainWindow.AddButton.ClickButton()




    Or, you could even reduce your alias down to

    Aliases.MainWindow_AddButton.ClickButton()




    Using Aliases, then, you can get rid of your Interface section in your code because then all your component aliasing is handled by TestComplete rather than in code and then your CodeCompletion works every time.


  • ngocvo3103_1's avatar
    ngocvo3103_1
    Occasional Contributor
    Hi Robert Martin,



    Thank you very much for answering me, I got your idea. I tried it and it worked well.



    Thanks,



  • Hello Ngoc Vo,





    As for the code completion feature, we have registered the issue in our database. We will try to improve this part of code completion functionality in one of the future updates.


  • ngocvo3103_1's avatar
    ngocvo3103_1
    Occasional Contributor
    Hello Allen,



    I love to hear that, hope we will get the update soon :)



    Thanks