Forum Discussion

SIStester's avatar
SIStester
Occasional Contributor
13 years ago

Getting the currently focused item's name

Hello, I'd like to accelerate the creation of my tests by making a script to enter dynamicly text in a textbox. The only information I'm lacking is how to put the "current software.current form.currently selected textbox" in delphi.



I tried something like the following(that index variable is only an increment to have a different name every time I run the test):





procedure texte(nom);

begin

  //Enters the text from the parameter in the currently selected text editor.

  ActiveControl.SetText(nom+inttostr(Project.Variables.index) );

end;





seems like ActiveControl isn't recognized by Testcomplete. Is there another way to do that?

5 Replies

  • SIStester's avatar
    SIStester
    Occasional Contributor
    OK I might have found a way to do this, but is there any way to capture the alias I used in the last action?



    In other words, I click in the textbox before entering text. Can I just keep the alias from that action? If so, how can I do that?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    There's an "Evaluate" function that, when you put a string in it, it will try to evaluate it back as an object.  so, you can do something like



    MyObject := Evaluate('Sys.Process(''MyApp'').MyForm.MyTextBox')




    You can then use MyObject in various places so long as it is in scope and reference the same text box.
  • SIStester's avatar
    SIStester
    Occasional Contributor
    thank you so much for looking into this, but I think I formulated that wrong..



    My software has many different textboxes in different forms (about 120 forms, 4-5 textboxes for every form). The goal here is to simply run the same script routine that sets the text in which I last clicked without having to send the object name in a procedure parameter.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    How did you determine what text box to click in the first place?  How did you figure out that name so you can call the appropriate "click" function?



    For that matter, clicking in a text box before entering text might be the wrong way about it.  Since you're using "SetText" already, you don't need to click on the text box first.
  • SIStester's avatar
    SIStester
    Occasional Contributor
    I click the textbox because that's what the clients do, I'm just recording a keyword test and replacing the SetText by my script.



    No need to look into this anymore, I decided to go with a low level script that inputs keys depending on what characters are in the string I send.



    Thanks for your help