How You Can Pass Parameters Between an Active Child and Inactive Parent
Another feature of the callframe statement is its ability to pass parameters by reference and by value. To pass a parameter by value, simply specify the parameter name and assign a value to it in the parameter list of the callframe statement.
For example, in the following statement, int_var, ref_var, and array_var are all parameters; and 2, check_out_row, and videos are their assigned values, respectively:
callframe myframe (int_var = 2, ref_var =
check_out_row,array_var = videos);
When you pass a simple variable, such as int_var, by value, any changes that you make to its value in the called frame are not reflected in the calling frame. For example, if myframe changes int_var to a value of 10, this change is not visible to the frame that called myframe. When myframe closes, int_var still has a value of 2 in the calling frame.
In contrast, when you pass a parameter that references a 4GL object or an array variable by value, any changes that you make to the object identified by the variable are reflected in the calling frame. This is because both array variables and variables referencing 4GL objects (reference variables) are pointers. When you pass a pointer to a called frame, both the called and the calling frame have a pointer to the same object. Consequently, any changes to that object in the called frame are visible in the calling frame when the called frame closes.
To pass a parameter by reference, you use the byref keyword. The syntax is:
callframe framename (parameter = byref(variable)
{, parameter = byref(variable)})
The following code is an example of this syntax:
callframe myframe (number = byref(int_var),
check_rec = ref_var,
movies = byref(array_var));
This example passes two variables by reference, number and movies,
; and one variable by value, check_rec. Because the variable passed by value references a 4GL object, changes made to the object in the child frame are visible in the parent frame.
Because the simple variable, number, was passed by reference, it also displays changes to the parent that are made in the child. When you pass a simple variable, such as int_var, by reference, any changes made to the parameter in the called frame are reflected in the variable in the calling frame after the called frame closes. Passing simple variables by reference, therefore, gives you a way to pass multiple return values to a calling frame.
Using the byref keyword to pass a reference or array variable lets you reassign the variable (a pointer) to a different object in the called frame and have that reassignment visible in the calling frame. The previous example shows how the array_var parameter is passed to myframe by reference. Consequently, if myframe reassigns the movies array variable to point to a different object, when myframe closes, array_var in the calling frame will also point to the new object.
In all cases, no changes reflected in the calling frame are visible until the called frame closes. At this point, the variable in the calling frame is updated the same way it would be if you had used an assignment statement. That is, if there is a field associated with the variable, it does not display the new value until the current event block completes. To cause the value to be updated before the end of the event block, use the Flush method immediately after the callframe statement. For more information about the Flush method, see the Language Reference Guide.