Filtering Objects in Delphi Open Applications

  June 26, 2006

Not long ago I tested a Delphi Open Application that contained a lot of objects which I didn’t need to test. All of these objects were displayed in the Object Browser panel, which annoyed me. I became much happier when I found out that in TestComplete 4.23 it’s possible to filter objects in Delphi Open Applications. This can be done by modifying the tcOpenAppClasses.pas file that is compiled into Delphi Open Applications. I tried it and I’m very satisfied with the results. Now TestComplete does not process the objects I do not need to test, and as a result, my scripts run much faster. In this blog, I’ll describe how you can modify the tcOpenAppClasses.pas file for your Delphi application.

Creating a sample application

I cannot use my application as a sample, since it’s too complex. I’ll tell you how to filter objects in a Delphi Open Application using a sample application that you can download from here.

First, create a new application project in Delphi. Name the project DelphiFiltration and save it to the <Program Files>Automated QATestComplete 4SamplesOpen AppsDelphiFiltration folder.

Now let’s make the application “Open”. To do this, you should include the tcOpenApp.pas, tcOpenAppClasses.pas and tcPublicInfo.pas files in it. Here is an excerpt from TestComplete’s help system that explains how to create a Delphi Open Application:

To create an Open Application:

  1. Include the files tcOpenApp.pas, tcOpenAppClasses.pas and tcPublicInfo.pas in your project. These files are located in the <TestComplete>Open AppsDelphi&BCB folder. Each of these files refers to the file that also resides in the previously mentioned folder. The file defines conditional symbols for different versions of Borland Delphi and C++Builder. tcOpenApp.pas uses the tcOpenAppHook dynamic link library. The TestComplete installation places this DLL into the <TestComplete>BinExtensions folder.

    To add files to your project, use Delphi’s or BCB’s Add to project dialog. To activate the dialog, select the Project | Add to Project menu item or press SHIFT-F11. (C++Builder will compile Delphi Pascal source files.)
  2. Recompile your project.

After you compiled your Open Application, launch it and switch to TestComplete’s Object Browser to see whether the application has become Open (the Object Browser displays the scales next to the DelphiFiltration process in the Object Tree).

Creating objects to be filtered

Let’s simulate a situation in which a lot of objects that we are not going to test are created. To do this, add a number of TAction and TMenuItem objects to the application. Save references to these objects to the ActionsArr and MenuItemsArr arrays that are members of the TForm1 class. You can perform these actions within the OnCreate event handler:

Don’t forget to delete the created objects within the OnDestroy event handler:

The number of created TAction and TMenuItem objects is specified by the ActionNums and MenuItremNums constants:

The code of the uMain unit now looks like this:

Now let’s run the application under test and TestComplete. Make sure that TestComplete’s Object Browser displays a lot of TAction and TMenuItem objects. The objects belong to the VCLObject("Form1") object of the DelphiFiltration process.

Filtering Objects

Now it’s time to filter the objects. To do this, we will tcOpenAppClasses.pas file. Copy this file from its original location - <TestComplete>Open AppsDelphi&BCBtcOpenAppClasses.pas - to your Delphi project folder (this will keep the original version of the file unchanged).

Correct the reference to the tcOpenAppClasses.pas file in your project file.

Open the tcOpenAppClasses.pas file for editing in Delphi’s Code Editor. Find the TtcComponentInfoProvider.GetChildComponent method. It has the following code:

This method provides information about Open Application objects to TestComplete (it returns a reference to an object). To make objects invisible to TestComplete, simply return nil for them. Our example contains the TAction and TMenuItem objects, which we do not need for testing. To hide these objects for TestComplete, write the following code for the method:

Now compile and run the application. Look at the Object Browser panel; the VCLObject("Form1") object of the DelphiFiltration process does not contain the TAction and TMenuItem objects and the VCLObject("Form1") now opens a lot faster. So, if you filter your application objects this way, TestComplete will execute your scripts a lot faster.