Generating Object Method Calls

Applies to TestComplete 15.42, last modified on September 08, 2022

Custom actions created with script extensions can generate script code that use calls to object methods. To generate an expression that contains a call to an object’s method, perform these steps:

  • Create a new InvokeSyntax object using the Syntax.CreateInvoke method.

  • Use the ClassValue and InvokeName of the created InvokeSyntax object to specify the object that contains the desired method and the method name, respectively.

  • Set the IsProperty property of the InvokeSyntax object to False.

  • If the target method uses parameters, use the AddParameter method of the InvokeSyntax object to specify the parameter values to be used in the generated code.

After you have configured the InvokeSyntax object, you can pass it to the Syntax.GenerateSource method to get the actual script code of the method call.

The example below demonstrates how you can generate a Log.Message method call:

JScript

function ShowMethodCallStatement()
{
    var oMethodCall = Syntax.CreateInvoke();
    oMethodCall.ClassValue = "Log";
    oMethodCall.InvokeName = "Message";
    oMethodCall.IsProperty = false;
    oMethodCall.AddParameter("Test");

    var strCode = Syntax.GenerateSource(oMethodCall);
    aqDlg.ShowMessage(strCode);
}

VBScript

Sub ShowMethodCallStatement
    Dim oMethodCall, strCode

    Set oMethodCall = Syntax.CreateInvoke
    oMethodCall.ClassValue = "Log"
    oMethodCall.InvokeName = "Message"
    oMethodCall.IsProperty = False
    oMethodCall.AddParameter "Test"

    strCode = Syntax.GenerateSource(oMethodCall)
    aqDlg.ShowMessage strCode
End Sub

The generated code is as follows:

JavaScript, JScript

Log.Message("Test");

Python

Log.Message("Test")

VBScript

Call Log.Message("Test")

DelphiScript

Log.Message('Test');

C++Script, C#Script

Log["Message"]("Test");

See Also

Generating Script Code
Generating Routine Calls
Generating Object Property Expressions
Generating Process, Window and Onscreen Object References
InvokeSyntax Object
CreateInvoke Method

Highlight search results