User Tools

Site Tools


prototyping_and_parameter_passing_in_the_application_generator.htm
Navigation:  How To's and Troubleshooting > How to… >====== Prototyping and Parameter Passing in the Application Generator ====== Previous pageReturn to chapter overviewNext page

NewC7.jpg

When calling procedures and functions, you may want to pass parameters, return values, or both. You can define (prototype) parameters and return values with the Procedure Properties dialog.

To pass parameters to a procedure, you must do the following.

·Add the parameters' datatypes to the prototype in the program's MAP

·Add the parameters' names to the PROCEDURE statement

·Pass the parameters in the procedure call

Adding Parameters to the Prototype

Use the Prototype field in the Procedure Properties dialog to redefine the Clarion Language prototype statement generated in the program's MAP. The prototype declares everything the calling program needs to know to call the PROCEDURE, including the data types of any parameters.

See also: PROCEDURE Prototypes and Prototype Parameter Lists .

For example, type (SHORT variablename,SHORT variablename),SHORT in the Prototype field to generate the following prototype statement in the program's MAP:

     MAP

      …

WindowsControls FUNCTION(SHORT ControlX,SHORT ControlY),SHORT

      …

     END

Notice the entire text from the Prototype field, including the parentheses, is appended to the prototype for the function. The words inside the parentheses are the datatypes and variable name of the parameters passed to the procedure or function. The word following the parentheses is the data type of the value returned by the procedure.

Adding Parameters to the PROCEDURE Statement

Type (SHORT ControlX,SHORT ControlY) in the Parameters field in the Procedure Properties (Actions) dialog to generate the following code for the procedure:

WindowsControls PROCEDURE(SHORT ControlX,SHORT ControlY)

Again, the entire text from the Parameter field, including the parentheses, is appended to the PROCEDURE statement.

In the Return Value field in the Procedure Properties dialog, press the ellipsis button (…) to select or define a return variable for the function, and to generate the following code. Note also the generated ProcedureReturn routine now RETURNs the value of the return variable you specified in the Return Value field: ReturnCode.

WindowsControls FUNCTION(SHORT ControlX,SHORT ControlY)

CODE

ProcedureReturn ROUTINE

 IF WindowOpened

   CLOSE(window)

 END

 IF LocalResponse

   GlobalResponse = LocalResponse

 ELSE

   GlobalResponse = RequestCancelled

 END

 POPBIND

 RETURN(ReturnCode)

TipBox.jpg

You should add embedded code to assign an appropriate value to the returned variable.

Calling the Procedure with Parameters

Use the Actions tab of the calling control (menu item, button, etc.) to pass parameters to a procedure or function.

Passing Parameters to Procedures

Go to the Actions dialog for the calling control.

In the When Pressed drop-down list, choose Call a Procedure.

In the Procedure Name drop-down list, choose the name of the procedure to call. If you have not yet defined the procedure, type it's name. You can define the new procedure later.

In the Parameters field, type the parameters to pass, separated by commas. The parameters may be literal values, expressions, or variable names.

Receiving Return Values from procedures

Although you may call a function with Call a Procedure from the Actions tab, and this method also allows you to receive return values.

Go to the Actions tab for the control.

In the When Pressed drop-down list, choose Call a Procedure.

In the Return Thread Variable (If you have the Initiale Thread box checked) or Return Value Variable (If you do not have the Initiale Thread box checked), type or select a variable name that will hold the Return Value.

prototyping_and_parameter_passing_in_the_application_generator.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1