winclass Declaration

Action

Declares a window class for an application-specific window or control.
Note: Window class declarations must appear outside of any function.

Syntax

[scope] winclass wclass-id [ : derived-class]
statements
Variable Description
scope Optional: Either public (the default) or private. Public declarations can be accessed from other files via a use statement. Private declarations are available only in the file in which they occur; you typically do not declare private window classes.
wclass-id An identifier specifying the name of the window class. This is the name you use to identify the class when you declare windows of that class.
derived-class Optional: An identifier specifying an existing window class on which you want to base the new class. The new class inherits all the window tags, variables, child window declarations, methods, and properties from the derived-class. Alternatively, if derived-class is the same as wclass-id and specifies an existing class, the statements extend the existing class definition.
statements Can include specification of a default window tag, and declarations for child windows, attributes, variables, methods, and properties.

Notes

  • Window classes for all the standard GUI objects are declared in the window class library, located in the file winclass.inc.

  • By declaring child windows in the window class declaration, all instances of that class are created with those child windows. Similarly, by declaring methods, properties, and variables in the window class declaration, you can use those methods, properties, and variables on all instances of that class.

  • You cannot extend a winclass that is defined in the same file, or in a file that is explicitly included in your file through the use statement. The original winclass definition must be in a separate .inc file that is included in the Runtime Options Use Files text box, or that is shipped with Silk Test Classic. You cannot extend AnyWin, Control or MoveableWin classes. They are logical (virtual) classes that do not correspond to any actual GUI objects, but instead define methods common to the classes that derive from them. For additional information, see Cannot extend AnyWin, Control, or MoveableWin Classes.

Derived Class

You have the option of deriving your new class from built-in classes or other user-defined classes. When you declare a class that is derived from another class, your class inherits the other class’s properties and methods. However, those methods and properties were implemented for the original class, and may not work with your new class. The custom class must truly be derived from, or at least must respond to the messages of, the derived from class in order for the derivation to be beneficial. Otherwise you will have to override the inherited methods and properties by reimplementing them in the new class declaration. You can also add additional methods and properties to your new class.

If you derive a class in one environment from a class for another environment, then the derived methods and properties may not work for the new class. For example, if you have a custom ActiveX or Java textfield, deriving it from TextField may work for SetText() if SetText() uses keystrokes (TypeKeys()), but probably will not work for GetText().

Declaring Child Windows

The syntax for declaring a child window within a window class declaration is the same as that used within a window declaration. See window Declaration.

Declaring Variables

The syntax for declaring variables within a window class declaration is the same as that used within a window declaration. See window Declaration.

Declaring Methods and Properties

You declare methods and properties for a new class within the class declaration. See Method Declaration and Property Declaration.

Declaring Attributes

The attributes associated with a window class are used by the GetEverything and VerifyEverything methods to get and verify information about a window. For additional information, see attribute Declaration.

Using Class-Specific Multiple-Tag Recording Options

By default, the Agent uses the multiple tags specified in the Record Declarations dialog box for all classes when recording and playing back. You can override which tags the Agent uses for a particular class using the setting statement. Anywhere within the winclass declaration for the class, include the following statement:
setting MultiTags = { tag-type[, tag-type]…}
where tag-type can be TAG_CAPTION, TAG_PRIOR_LABEL, TAG_INDEX, TAG_WINDOW_ID, or TAG_LOCATION.
For example, the following code fragment:
[-] winclass MyList : RadioList
	[ ] setting MultiTags = {TAG_CAPTION}
tells the agent to use only the Caption tag for the MyList class.

Controlling Which Window Class is Recorded

The default behavior of Silk Test Classic is to tag all instances of the parent class as the new class. So, if you record a window declaration against a standard object from which you have defined a new class, Silk Test Classic records that standard object’s class as the new class.

As long as there is no tag included in the declaration of the new class, you can have all instances declared by default as the original class. To do so, add the following statement to the declaration of your new class:

setting DontInheritClassTag = TRUE

Since the presence of a tag for the class will override the DontInheritClassTag setting, however, the following declaration would cause a dialog box to be declared as a FileDialog, not a DialogBox:

[-] winclass FileDialog : DialogBox
	[ ] tag "[DialogBox]"
	[ ] setting DontInheritClassTag = TRUE
If the base class of a new winclass is itself declared in a winclass declaration, then the same criteria will apply. For example, the addition of the following declaration to the example above would cause a dialog box to be declared as FileDialog:
[-] winclass SpecialFileDialog : FileDialog
	[ ] setting DontInheritClassTag = TRUE
Adding the following line:
tag "[DialogBox]"
to the declaration of SpecialFileDialog would cause a dialog box to be declared as SpecialFileDialog.

For example, assume you define a new class called FileDialog and derive it from the DialogBox class. Then you record a window declaration against a dialog box. Silk Test Classic records the dialog box to be of the new FileDialog class, instead of the DialogBox class.

To have Silk Test Classic declare the dialog box’s class as DialogBox, in the FileDialog definition, set DontInheritClassTag to TRUE. For example:
[-] winclass FileDialog : DialogBox
	[ ] setting DontInheritClassTag = TRUE

Examples

[-] winclass NewPushButton : PushButton
	[ ] property sLabel
	[-] STRING Get ()
		[ ] return (GetCaption ())
[-]   STRING GetLabel ()
		[ ] return (GetCaption ())
	[ ] 
[-] winclass NewDialogBox : DialogBox
	[-] NewPushButton OK
		[ ] tag "OK"
	[-] NewPushButton Cancel
		[ ] tag "Cancel"
	[-] NewPushButton No
		[ ] tag "No"
	[-] NewPushButton Yes
		[ ] tag "Yes"
	[-] NewPushButton FindNext
		[ ] tag "Find Next"
	[-] void Tab (INTEGER iTimes optional)
		[ ] // declare method that tabs x times in dialog box
		[-] if (iTimes == NULL)
			[ ] iTimes = 1
		[ ] TypeKeys ("<tab {iTimes}>")