Forum Discussion

VasanthVijay's avatar
VasanthVijay
Contributor
9 years ago

Using of USER FORMS Test complete get crash?

Hello,

 

function UserForm1_OnShow(Sender)
{
var form;
UserForms.UserForm1.Visible =true;
UserForms.FormByName("UserForm1").Show();
}

 

function sa()
{
UserForm1_OnShow()
}

 

By using the above code testcomplete application crash.

Why it happen?

 

1 Reply

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    From your code, it looks like UserForm1_OnShow is an event handler assigned to the form's Show event. Calling Show() inside this event handler creates an infinite recursion, which causes the crash.

     

    There're two ways to show a form.

     

    1) Modal mode - the script is paused until the user closed the form.

     

    function sa()
    {
      var res = UserForms.UserForm1.ShowModal();
    
      if (res == mrOK) {
         Log.Message("Form was closed via OK button.");
      }
      else {
         Log.Message("Form was closed via another button.");
      }
    }

    For this to work, make sure to set the ModalResult property of the form buttons in the form designer. Example for the OK button:

     

    OK button

     

    2) Non-modal mode - the script execution continues after the form is displayed, and the script should explicitly close the form when it's no longer needed.

     

    function sa()
    {
       UserForms.UserForm1.Show();
    
    // Do something // ... UserForms.UserForm1.Hide(); }

     

    Hope this helps!