Providing Access to Global Objects in Delphi Open Applications
Test and Monitor | Posted June 26, 2006

By default TestComplete provides access to visual objects of Delphi Open Applications. Non-visual objects can only be obtained through methods and properties of visual objects. For instance, you cannot work with the Application object unless a reference to it is returned by a form’s method or property.

Inaccessibility of global objects can sometimes be inconvenient, since tests cannot use certain functionality provided by these objects. I was very happy to find that TestComplete offers a workaround for the problem. It turns out that access to global or non-visual objects is possible by modifying the tcOpenAppClasses.pas file that is compiled into each Delphi Open Application.

Before I start describing the workaround, I’d like to note that the described approach works only for those global or non-visual object that are TComponent descendants.

Below are the steps for the workaround:

  1. Create a new Delphi application.
  2. To make the application “Open”, you need to include the tcOpenApp.pas, tcOpenAppClasses.pas and tcPublicInfo.pas files. These files reside in the <TestComplete>OpenAppsDelphi&BCB folder. Add the tcOpenApp.pas and tcPublicInfo.pas files to your project. Copy tcOpenAppClasses.pas to your project folder and then add the copy to the project (we will change the copy to provide access to global objects. Copying ensures that you have the original version of the file unchanged).
  3. To provide access to the desired global or non-visual object, modify the code for the TtcTopComponentProvider.GetComponent and TtcTopComponentProvider.GetCount functions. They are used to enumerate top-level objects of Open Application processes. The original code of these functions look like:

    [code lang="js"]

    function TtcTopComponentProvider.GetComponent(Index: Integer): Pointer;

    begin

    Result := Screen.DataModules[Index];

    end;

    function TtcTopComponentProvider.GetCount: Integer;

    begin

    Result := Screen.DataModuleCount;

    end;

    [/code]

After making the above changes, recompile and launch your application. Look at TestComplete’s Object Browser panel; your application process has the node VCLObject("TApplication") that corresponds to the global Application object. If you select this node in the Object Tree, the Object Browser will show the object’s members in the Properties, Methods and Events tabbed pages. Note that it can take time to open these pages as the TApplication class contains a lot of methods and properties.

Using the described approach you can expose other global or non-visual objects that you need to use in your tests. You can also download a sample application that demonstrates this approach.

 

Close

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox