Calling Methods and Functions

Method Calls

A method is a routine that applies to a particular class of objects. Once an object is declared, you can refer to it by its identifier when calling methods.

The following example calls the SetActive method on the Find dialog box:
Find.SetActive ()

You can call methods for a window that has not previously been declared using a special identifier for dynamic instantiation. The syntax varies depending on whether you use INC files. When you record a test case with the Open Agent, Silk Test Classic creates locator keywords in an INC file to create scripts that use dynamic object recognition and window declarations. You can also manually create test cases that use dynamic object recognition without an INC file. Dynamic object recognition uses a Find or FindAll function and an XPath query to locate the objects that you want to test. No INC file, window declarations, or tags are required.

Use the following syntax with INC files:
class("tag").class("tag"). ...
The following example calls a method on a dynamic instantiation of Find:
MainWin("Text Editor -*").DialogBox("Find").SetActive ()
Use the following syntax without INC files:
Findclass name(locator). ...
The following example calls a method on a dynamic instantiation of Find:
FindMainWin("@caption=’Text Editor -*’").FindDialogBox("Login").
   FindTextField("@priorlabel=’password’").TypeKeys("top secret")

Function Calls

A function is a routine that does not pertain to any particular object. Silk Test Classic provides some functions that are available in most other programming languages, such as functions for manipulating strings and numbers, and some functions that are unique to testing requirements.

To call a function, you do not refer to any objects. Instead, you just call the function directly. The following example calls the Abs function, which calculates the absolute value of a number:
First = Abs (iFirst)

Specifying Arguments

Consider the SetMultiText method, which can accept three arguments:

textfield.SetMultiText(lsText [, iStartLine, iNumLines])

The first argument, lsText, is required; you must include it when calling SetMultiText. The two arguments shown inside of brackets are optional. However, if you use the first one, you must also use the second because iNumLines counts lines of text starting from iStartLine.

The AddDateTime function, can accept six arguments:
newDT = AddDateTime(Datetime[, iDays, iHours, iMins, iSecs, iMsecs])

The first argument, Datetime, is required; the five arguments shown inside of brackets are optional. However, if you specify one, you must also specify any of the optional arguments that precede that one.

Use NULL for arguments that need no value specified. For example, the following code adds one hour to the Datetime value in newDateTime.
newDateTime = AddDateTime (datetime, NULL,1)

Out and Inout Arguments

Some functions and methods have arguments specified as inout or out. These specifications indicate that the function or method can change the value of the argument. For more information, see Function Declaration.

Return Values

Some methods and functions return values. You can provide a variable to hold the returned value, as in the first example below, or use the function or method call in another expression, so that the returned value becomes the value passed to the expression.

// return GUITYPE to variable gtype
GUITYPE gtype = GetGuiType ()
// pass font size to Verify function
Verify (MyDialog.RichEdit1.GetFontSize (4, 1), 12)

The second example passes the font size of the character in the first column of the fourth row to the Verify function, which verifies that the size is 12.

Passing the Name of the Function or Method to a Test

You can use the ArgListCall keyword to pass the name of the function or method, along with its arguments, at runtime in data-driven tests.