Calling Functions and Events

Syntax for calling functions and events

Supported

  • The syntax used to call all PowerBuilder functions and events:

    {objectname.} {type} {calltype} {when} name ({argumentlist})

    If the calltype argument is DYNAMIC, it is unsupported to specify a reference argument in the argumentlist.

  • The syntax used to call functions and events in an object's ancestor:

    {objectname.} ancestorclass ::{type} {when} name ({argumentlist})
  • If the function name is not qualified with an object or a control, PowerBuilder searches for the function and executes the first one it finds that matches the name and arguments. This is supported in PowerServer.

Unsupported

  • Referring to a global function by using the global scope operator (::) before the function name is unsupported.

Triggering & Posting

Triggering

Supported

  • Triggering for functions

  • Triggering for events

Unsupported

For application and message objects, triggering for functions and events are unsupported.

Posting

Supported

  • Posting for functions

  • Posting for events

  • Posting function B that is called inside function A. For example:

    Function A ()
    {
    ......
    Post Function B () //unsupported to post function B
    ......
    }
    

Unsupported

Posting a function containing reference arguments, which is a local variable is unsupported. Please use the instance variable to replace the local variable to work around this unsupported feature.

Post function

Supported

There are three POST syntax supported, and two of them are supported with limitations.

  • Post Close(window)

  • Post Open(window)

    Limitations: the window argument cannot be an array variable. For example, the following script is unsupported:

    //Unsupported
    window winname[2]
    .....
    Post open(winname[1],....)
    - Post open(windowvariable)
    
  • Post user_function()

    Limitations: The reference argument cannot be a local variable. For example, the following script is unsupported:

    //Unsupported
    Integer gf_string (ref string as_parm1)
    Post gf_String(ls_Parm) // ls_parm is a local variable.
    

Static & dynamic calls

Supported

  • Static calls to functions

  • Static calls to events

  • Dynamic calls to functions

  • Dynamic calls to events

Unsupported

  • Dynamic calling for overloaded functions is unsupported.

  • Dynamically calling a function that has an argument passed by reference is unsupported.

  • If a function is dynamically called, its return value cannot be passed as an argument of another function.

  • Nested call of more than one layer dynamic code is unsupported, for example,

    ll_row2 = invo_test.dynamic of_dynamic1(invo_test.dynamic of_dynamic2(ll_row))

    The workaround is to execute the dynamic nested call separately. The above example should be modified as below:

    tt = invo_test.dynamic of_dynamic2(ll_row)
    ll_row2 = invo_test.dynamic of_dynamic1(tt);
    

Overloading, overriding, and extending functions and events

Supported

  • Function overriding is supported.

  • Extending and overriding events are supported.

Unsupported

  • Overloading system functions is unsupported.

  • Dynamic calling for overloaded functions is unsupported.

  • Overloading a function that has a dot notation as an argument is unsupported. For example, overloading the following function is unsupported:

    wf_getname(dw_1.object.s_id[1])
  • Using the local variable AncestorReturnValue in an event of a descendant object is unsupported, unless the event of the descendant object is an extended event from the ancestor object.

  • The following scenario is unsupported:

    In object A (parent object), function g() calls function f(type1 arg 1).

    g()
    {
    f(type1 arg1);
    }
    

    In object B (child object), function f(type2 arg2) is the overloading function of function f(type1 arg 1), and object B inherits function g() from object A.

  • Object type of passed parameter must exactly match with the declaration of function overloading. For example, in the following overloading function, the object type of the third parameter is n_tr:

    public function integer of_register (string as_id, string as_dwobjectname, n_tr atr_obj, boolean ab_initialload)
    public function integer of_register (string as_id, string as_dwobjectname, n_tr atr_obj, any aa_args[20])
    public function integer of_register (string as_id, string as_dwobjectname, n_tr atr_obj, any aa_args[20], boolean ab_initialload)
    

    In the following script that calls the above function, if the third parameter sqlca is not n_tr, for example, it is an ancestor of n_tr or a descendant of n_tr, Appeon might call the wrong function.

    gnv_app.inv_dwcache.of_register('inventory_header','d_inventory_data', sqlca, la_args)

Passing arguments to functions and events

Passing arguments

There are three ways to pass arguments to functions and events:

  • By value

  • By reference

  • Read-only

Arguments can be passed with one limitation that each function or event can have a maximum of 20 arguments. If the number of arguments exceeds 20, the arguments after the 20th argument will be invalid.

Unsupported

  • If both function A and function B have an argument passed by reference,calling function A that has one argument calling to function B, while the argument (that is passed by reference) in the two functions uses the same variable, is unsupported.

    For example:

    Supported syntax:

    f(int a, ref int b); g(ref int a)

    Unsupported syntax:

    f(g(a), a)
  • Function A has two arguments passed by reference. It is unsupported for the two arguments to use the same variable.

    For example:

    Unsupported syntax:

    f(a,a) //f(ref int a, ref int b)
  • Passing a property dot notation as the function argument is unsupported if the property refers to an object, however, this can be worked around.

    For example:

    Unsupported syntax:

    lvn_security.Of_setmenuright(this.MENUID)

    Workaround:

    menu m_1 = this.MENUID
    lvn_security.Of_setmenuright(m_1)
    
  • Passing an argument that is an object property by reference is unsupported.

    Example:

    Unsupported example:

    /*Define a function of_display()*/
    public Function string of_display(ref string str_data)
    ...... //The code in the function
    return str_data
    end function
    /*Call to the function in the Clicked event of a CommandButton control*/
    string ls_string1
    ls_string1 = of_display(this.text)
    

Using return values of functions and events

Supported

To use the return value, assign it to a variable of the appropriate data type or call the function where you can use a value of that data type:

  • Return values for built-in PowerScript functions

  • User-defined functions or events that have return values

  • Return values for system events

  • User-defined events that have return values

  • The function has parameters of standard data type passed by reference and the return value is used as a condition in RETURN, IF ... THEN, CHOOSE...ASE, or DO ... LOOP statements.

  • The function has parameters of object data type passed by value and the return value is used as a condition in RETURN, IF ... THEN, CHOOSE...ASE, or DO ... LOOP statements.

  • The return value of one function is used as the parameter of another function, for example, func1(func2()).

To use cascaded call and return values:

  • It is supported to get/set the property of an object that is the return value of a function:

    Syntax:

    function.property

    For example:

    ParentWindow( ).Enabled = TRUE
  • It is supported to call the function of an object that is the return value of a function.

    Syntax:

    function1.function2

    For example:

    ParentWindow( ).Hide( )
    Ls_test = String(m_main.GetParent( ).ClassName( ))

Limitations of using cascaded call and return values:

  • It is unsupported to use the DYNAMIC keyword

  • Except for the first call in the chain of cascaded calls, it is unsupported to use reference arguments.