|This method is obsolete. See the Remarks section below.|
VarToWString functions are used to convert variant values to a specific type. TestComplete scripts use OLE variant variables which can take different variant types. When they are used as parameters or as terms in an expression, an implicit conversion takes place to assign them the type implied by the context. However, sometimes the script interpreter needs help. For instance, if you mean to concatenate a string-variant with an integer-variant, using the + sign (or & in VBScript), you should convert the second term to string-variant type first:
resultString = string1 + VarToString(int2)
Calling methods, functions or procedures in an Open Application from TestComplete scripts may likewise require preprocessing for their parameters. In most cases, the conversion from the OLE variant to the native application type and back is performed automatically. But there are cases where the script interpreter is unable to determine the needed native type definitely. The two most frequent cases are -
FuncU(varValue)in Object Pascal or void
FuncU(void * U)in C++, and
Take the Object Pascal example. A pointer to a char or to a byte are both the addresses of one byte in memory. It just happens that a convention allows us to pass the starting address of an array of chars as a
PChar. Where application source says
FuncA(A : PChar), at runtime nothing indicates if the parameter is a string, or a byte being passed by reference.
Therefore, TestComplete supplies
VarToFloat so that you may specify the native type of parameters for application routines. For instance, in the following code
VarToString specifies that
FuncA needs a null-terminated string as a parameter:
i = "12" w.MyForm.FuncA(VarToString(i))
These "functions" are more in the nature of compiler directives. The effect of putting one in a parameter list is to override the interpreter's default conversions. Other ambiguous parameters in the list will also need
VarToxxx, even though normally they would be converted transparently. For instance,
TMyForm = class (...)
procedure FuncA(A : PChar; var C : BYTE);
// Script routine
w.MyForm.FuncA(VarToString("Hello"), myNum); // Error!!!
w.MyForm.FuncA(VarToString("Hello"), VarToInteger(myNum)); // Correct
# Script routine w.MyForm.FuncA(VarToString("Hello"), myNum) # Error!!! w.MyForm.FuncA(VarToString("Hello"), VarToInteger(myNum)) # Correct
' Script routine
Call w.MyForm.FuncA(VarToString("Hello"), myNum) ' Error!!!
Call w.MyForm.FuncA(VarToString("Hello"), VarToInteger(myNum)) ' Correct
// Script routine
w.MyForm.FuncA(VarToString('Hello'), myNum); // Error!!!
w.MyForm.FuncA(VarToString('Hello'), VarToInteger(myNum)); // Correct
// Script routine
w["MyForm"]["FuncA"](VarToString("Hello"), myNum); // Error!!!
w["MyForm"]["FuncA"](VarToString("Hello"), VarToInteger(myNum)); // Correct
VarToBool is typically used in script instructions that compare the value of a property or a field exported from an Open Application. TestComplete reads boolean properties and fields as integers: False is 0, True is any other integer value, e.g. 1 or -2. Without the
VarToBool conversion, some comparison instructions (typically in VBScript procedures) may produce incorrect results.
|These methods are obsolete. They are supported for backward compatibility only.|
|Result||A value of a specific type.|
The method is applied to the following object:
The method has the following parameter:
A variant value to convert.
A value of a specific type.
These methods are obsolete. They are supported for backward compatibility only. To convert variant values to values of specific types, use the methods of the aqConvert object.