Using Structures in Scripts

Applies to TestComplete 15.0, last modified on October 22, 2021
Information in this topic applies to desktop applications only.

Scripting languages only use OLE compatible data types. Though structures are not OLE-compatible types, you can create and use them in TestComplete. All structures can be divided into three categories:

Win32 API and VCL Structures

Most of these structures are provided by the Win32API and Utilities scripting objects. If a structure is not supported by these objects, you can always create it in the same way as you create user-defined structures. The most convenient way to determine if TestComplete supports a predefined structure is to use the Code Completion window.

For each supported structure, there is a special wrapper object. These objects are created by functions that have the same names as the structures. Therefore, instead of declaring the type of a structure variable, you call a function using the type name, and get an OLE object wrapping for the wanted structure, which you assign to your variable. For instance, to use the TRect structure (a VCL analogue of the Windows API RECT structure), you call the TRect function:

JavaScript, JScript

structRect = TRect();

Python

structRect = TRect()

VBScript

Set structRect = TRect

DelphiScript

structRect := TRect;

C++Script, C#Script

structRect = TRect();

The wrapper objects contain properties matching structure members, and using the same names. For instance, the following code sets the left and top bounds of the TRect structure:

JavaScript, JScript

structRect.Left = 10;
structRect.Top = 10;

Python

structRect.Left = 10
structRect.Top = 10

VBScript

structRect.Left = 10
structRect.Top = 10

DelphiScript

structRect.Left := 10;
structRect.Top := 10;

C++Script, C#Script

structRect["Left"] = 10;
structRect["Top"] = 10;

Once you have obtained a VCL or Win32 structure, you can pass it to the appropriate function(s) as a parameter.

Note, that if a function stores data to a structure passed to this function by reference, you should create this structure using the appropriate method before passing it to the function. For instance:

JavaScript, JScript

function TestDateTimeToSystemTime()
{
  var DT, ST;

  DT = Utilities.Now();
  ST = Win32API.TSystemTime();
  Utilities.DateTimeToSystemTime(DT, ST);
  Log.Message(ST.wYear);
}

Python

def TestDateTimeToSystemTime():
  DT = Utilities.Now()
  ST = Win32API.TSystemTime()
  Utilities.DateTimeToSystemTime(DT, ST)
  Log.Message(ST.wYear)

VBScript

Sub TestDateTimeToSystemTime
  Dim DT, ST

  DT = Utilities.Now
  Set ST = Win32API.TSystemTime
  Utilities.DateTimeToSystemTime DT, ST
  Log.Message ST.wYear
End Sub

DelphiScript

procedure TestDateTimeToSystemTime;
var DT, ST;
begin
  DT := Utilities.Now;
  ST := Win32API.TSystemTime;
  Utilities.DateTimeToSystemTime(DT, ST);
  Log.Message(ST.wYear);
end;

C++Script, C#Script

function TestDateTimeToSystemTime()
{
  var DT, ST;

  DT = Utilities["Now"]();
  ST = Win32API["TSystemTime"]();
  Utilities["DateTimeToSystemTime"](DT, ST);
  Log["Message"](ST["wYear"]);
}

User-Defined Structures

To create custom structures, you can use the Object-Driven Testing (ODT) editor and program objects. The editor and the objects let you define custom classes and create objects of these classes. Such objects can be used as wrapper objects for structures. See Object-Driven Testing for more information.

One more way to create custom structures is to use the DLL object. It provides methods that let you create structures with custom fields. You can find examples of creating custom structure via methods of the DLL object in the following topics:

Structures Passed as Parameters to DLL Routines

When you call a routine from a dynamic link library using methods and properties of the DLL object, you cannot use wrappers or structures provided by the Win32API and Utilities objects. The DLL object does not support them. This object provides its own mechanism for creating and defining structures. See Calling DLL Functions From Tests - Tutorial for detailed information.

See Also

Calling DLL Functions From Tests - Tutorial
Calling Win32 API Functions
Utilities Object
Object-Driven Testing

Highlight search results