ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / WLanguage procedures
  • Creating a procedure
  • Exiting from a procedure
  • "At the end of the event containing the call"
  • Returning a result
  • Stamping the return value
  • Extension attributes
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
The method for declaring a procedure is the same no matter whether it is:
Important: You must not declare two procedures with the same name (especially a global procedure and a local procedure).
Reminder: In WLanguage, there is no distinction between the procedures and the functions. The syntaxes for declaring and using procedures also apply to functions.
Example
PROCÉDURE Find(FileName, Key, Value)
HReadSeek(FileName, Key, Value)
IF HFound() = True THEN
RETURN True
ELSE
RESULT False
END
Syntax

Declaring a procedure with parameters Hide the details

PROCEDURE <Procedure name>(<Parameters>) [<Extension attributes>] [: <Type of return>]
<Procedure code>
<PROCEDURE>:
Start of procedure declaration.
Remark: To make your programs more readable, the PROCEDURE keyword can be replaced with the FUNCTION keyword.
<Procedure name>:
Name of the procedure to be declared.
<Parameters>:
Parameters passed to the procedure. Each parameter is separated by a comma. For more details on parameters, see Procedure parameters.
If your procedure or function uses a project element (window, page, report, ...), you have the ability to get the list of requested elements in the completion. To do so, add an extension attribute into the declaration of the function or procedure parameters.
<Extension attributes>:
Extension attributes used to define the options for managing the code editor. For more details on the available extension attributes, see the remarks.
<Type of return>:
Type of value returned by the procedure. This type can correspond to a simple type (integer, real, string...) or to a structured type (structure, object...).
This information is used to make sure that the procedure always has the same type of value in return. The returned value will always be converted to the specified type.
For example, if the return type is "Integer" and if the returned value is a string, the string will be automatically converted to integer.
<Procedure code>:
WLanguage code of procedure to declare.

Declaring a procedure without parameter Hide the details

PROCEDURE <Procedure name>() [<Extension attributes>] [: <Type of return>]
<Procedure code>
<PROCEDURE>:
Start of procedure declaration.
Remark: To make your programs more readable, the PROCEDURE keyword can be replaced with the FUNCTION keyword.
<Procedure name>:
Name of the procedure to be declared.
<Extension attributes>:
Extension attributes used to define the options for managing the code editor. For more details on the available extension attributes, see the remarks.
<Type of return>:
Type of value returned by the procedure. This type can correspond to a simple type (integer, real, string...) or to a structured type (structure, object...).
This information is used to make sure that the procedure always has the same type of value in return. The returned value will always be converted to the specified type.
For example, if the return type is "Integer" and if the returned value is a string, the string will be automatically converted to integer.
<Procedure code>:
WLanguage code of procedure.

Declaring a procedure with variable parameters Hide the details

PROCEDURE <Procedure name>(<Parameters>, ]*) [<Extension attributes>] [: <Type of return>]
<Procedure code>
<PROCEDURE>:
Start of procedure declaration.
Remark: To make your programs more readable, the PROCEDURE keyword can be replaced with the FUNCTION keyword.
<Procedure name>:
Name of the procedure to be declared.
<Parameters>:
Parameters passed to the procedure. Each parameter is separated by a comma.
If the number of parameters that can be passed to the procedure changes, use the "*" symbol. For example:
  • Procedures that can receive between 0 and 255 parameters: Procedure MyProc(*).
  • Procedures that can receive between 1 and 255 parameters: Procedure MyProc(Param1, *).
For more details, see:
<Extension attributes>:
Extension attributes used to define the options for managing the code editor. For more details on the available extension attributes, see the remarks.
<Type of return>:
Type of value returned by the procedure. This type can correspond to a simple type (integer, real, string...) or to a structured type (structure, object...).
This information is used to make sure that the procedure always has the same type of value in return. The returned value will always be converted to the specified type.
For example, if the return type is "Integer" and if the returned value is a string, the string will be automatically converted to integer.
<Procedure code>:
WLanguage code of procedure to declare.
Remarks

Creating a procedure

For more details on how to create a global procedure, see Global procedures.
For more details on how to create a local procedure, see Local procedures.

Exiting from a procedure

To force the exit from a procedure, use the RETURN keyword. In the procedure, none of the processes after the RETURN keyword are executed.
For example:
PROCÉDURE Calculate(Dividend)
IF Dividend = 0 THEN
Error("Unable to divide by zero")
RETURN
ELSE
...
END
Remarks:
  • If the procedure returns a result, use the RETURN keyword.
  • The RETURN and RETURN keywords cannot be used in the same process.

"At the end of the event containing the call"

The procedures with the option "At the end of the event containing the call" enabled, and called from a callback procedure (procedure used by fListFile, Event, etc.) are executed at the end of each call to the callback.
Example:
// -----------------
// standard case
// -----------------
Click of button
// beginning of button click code
Proc1
// beginning of Procedure1 code
Proc2
// beginning of Procedure2 code

Call to EndEvent procedure
// end of Proc2 code
// end of Proc1 code
// end of button click code
Execution of EndEvent procedure
// -------------------
// callback case
// -------------------
Click of button
Proc1
Proc2
use of fListFile
Callback1 procedure
// beginning of code of Callback1 Procedure
CallbackProc2
// beginning of code of Callback2 Procedure
Call to ProcEndEvent
// end of ProcedureCallback2 code
// end of ProcedureCallback1 code
Execution of ProcEndEvent
ProcedureCallback1
// beginning of ProcedureCallback1 code
ProcedureCallback2
// beginning of ProcedureCallback2 code
Call to ProcEndEvent
// end of ProcedureCallback2 code
// end of ProcedureCallback1 code
Execution of ProcEndEvent

Returning a result

To return the procedure result to the calling process, use RETURN. This keyword is used to return:
  • a value,
  • several values.
For example:
// Procedure that returns a value
PROCÉDURE Find(FileName, Key, Value)
HReadSeek(FileName, Key, Value)
IF HFound() = True THEN
RETURN True
ELSE
RESULT False
END
// Procedure that returns several values
PROCÉDURE MyProc()
 
// Process
RETURN (1, 2, 3)
 
 
// Code for calling the procedure
( x, y, z ) = MyProc()
// x is set to 1, y to 2 and z to 3
Tip: For the procedures that return a result, we recommend that you use the FUNCTION keyword instead of PROCEDURE to simplify the code reading.
Important: The RETURN keyword must not be used to force the exit from a procedure that returns a result. The procedure call expects a status report that will not be returned if the exit from the procedure is forced.

Stamping the return value

To specify the type of return value, all you have to do is specify this type (preceded by ':') when declaring the procedure. For example:
PROCEDURE Calculation(): int
 
IF MyExpression = True THEN
RETURN "1"  // The string "1" will be converted to integer
ELSE
RETURN 0
END
Remark: Multiple return values
You have the ability to assign a type to the return values. The syntax is as follows:
PROCEDURE ProcedureName(): ([<Type value 1>, [<Type value 2>, ... , [<Type value N>]]])
Remark: There is no need to specify the type for all return values. To avoid specifying the type of a return value, all you have to do is omit the type or use the '?' character.
Example:
PROCEDURE Procedure_Name(): (string..string)
 
RESULT(1,2,3)

PROCEDURE Procedure_Name(): (string,?,string)
 
RESULT(1,2,3)
The following types of return values are allowed:
TypesChecks performed during the compilationChecks/Actions performed at runtime
booleanAutomatic WLanguage conversions
unsigned intAutomatic WLanguage conversions
unsigned 8-byte intAutomatic WLanguage conversions
intAutomatic WLanguage conversions
8-byte intAutomatic WLanguage conversions
system intAutomatic WLanguage conversions
currencyAutomatic WLanguage conversions
numericAutomatic WLanguage conversions
realAutomatic WLanguage conversions
4-byte realAutomatic WLanguage conversions
characterAutomatic WLanguage conversions
stringAutomatic WLanguage conversions
ANSI stringOnly the strings without size are allowedAutomatic WLanguage conversions
UNICODE stringOnly the strings without size are allowedAutomatic WLanguage conversions
bufferOnly the strings without size are allowedAutomatic WLanguage conversions
dateAutomatic WLanguage conversions
timeAutomatic WLanguage conversions
datetimeAutomatic WLanguage conversions
durationAutomatic WLanguage conversions
procedureOnly the Procedure types are allowedOnly the Procedure types are allowed
fontOnly the Font types are allowedOnly the Font types are allowed
<enumeration>
<combination>
<class>
  • "dynamic" is not allowed
  • The classes must be correlated
Conversions allowed only
<structure>
  • "dynamic" is not allowed
  • the structures must be the same.
The structures must be the same.
<advanced type>
  • "dynamic" not allowed
  • The advanced types must be the same.
The advanced types must be the same.
<.NET class>"dynamic" not allowed
array
  • "dynamic" not allowed
  • Checking the type of elements
  • Checking the number of dimensions
  • Checking the type of elements
  • Checking the number of dimensions if the dimensions are supplied,
  • Checking each dimension
associative arrayChecking the type of elementsChecking the type of elements
stackChecking the type of elementsChecking the type of elements
queueChecking the type of elementsChecking the type of elements
listChecking the type of elementsChecking the type of elements

Extension attributes

The available extension attributes are:
  • extension attribute for managing zombie procedures:
    <zombie [comment = "text"]>Used to define an obsolete procedure (also called zombie procedure). The optional comment keyword is used to indicate the text that will be displayed in the compilation error associated with the obsolete procedure. For more details, see Zombie procedures.
  • extension attribute for managing the debugger:
    <without step by step>Used to specify that the procedure will be ignored by the debugger when debugging in "Step by step" mode.
  • extension attributes specific to local, global or internal procedures:
    "<extension>"Indicates that the procedure is an extension procedure. This WLanguage procedure can be used with a WLanguage type as a native WLanguage function. For more details, see Extension procedure.
    <automatic>Used to specify that this procedure will be run automatically after the initialization code (of the window, page or project).

    This extension attribute is not compatible with <thread> and <main thread>.

    Additionally, you can see the help about Automatic procedures.

    Caution, this extension attribute cannot be applied to an internal procedure.
    <end event>Used to specify that this procedure will be executed when the process containing the procedure call is finished. For more details, see "At the end of the event containing the call".

    This extension attribute is not compatible with <thread> and <main thread>.

    Additionally, you can see the help about Automatic procedures.
    <end process>Used to specify that this procedure will be executed when the process containing the procedure call is finished.

    This extension attribute is not compatible with <thread> and <main thread>.

    Additionally, you can see the help about Automatic procedures.
  • extension attribute to manage timers:
    <call again[=type of call]>Used to specify, in a procedure called in a Timer, the operating mode of subsequent calls. This extension attribute must be used with <timer>. The optional value of this extension attribute can be:
    ignore
    (Default value)
    The procedure is called immediately. There is no wait time for calling the procedure. The procedure is called only once without repetition.
    newA new Timer is triggered. The procedure is called in this new Timer.
    Caution, the previous Timer has not stopped. The Timers will pile up in memory.
    restartUsed to restart the Timer automatically at the end of the procedure. <Interval> is used to define the time interval between each call to the procedure.
    This extension attribute is not compatible with <thread> and <main thread>.

    Additionally, you can see the help about Automatic procedures.
    <delay=duration in hundredths of a second>Used to specify the wait time before the start of the procedure in a Timer (during the first call). This extension attribute must be used with <timer>. The optional value delay in hundredths of a second allows you to specify this wait time.
    If this value is not specified, you must specify this value when using <timer>.

    This extension attribute is not compatible with <thread> and <main thread>.

    Additionally, you can see the help about Automatic procedures.
    <interval=duration in hundredths of a second>Used to specify the duration (interval) between 2 calls to the procedure.
    This extension attribute must be used with <timer> or <repetition>. The optional value interval in hundredths of a second allows you to specify this time interval.
    If this value is not specified, you must specify this value with <timer>.

    This extension attribute is not compatible with <thread> and <main thread>.

    Additionally, you can see the help about Automatic procedures.
    <repetition [=number of repetitions]>Used to specify that the procedure is called several times in a row (repetitions). The optional value number of repetitions is used to specify the number of calls to the procedure.
    • If this value is not specified, the repetition will go on until:
      • EndAutomatedProcedure is called.
      • the element to which the procedure belongs is closed (window, page, report).
      • the instance to which the procedure belongs is destroyed (for more details about the concept of instance, see the help on Instantiating an object).
      • the end of the application (application closed by the user, or use of EndProgram).
    • If this value is specified, the procedure will be called as many times as the specified number.
    Additionally, you can see the help about Automatic procedures.
    <timer [=intervals in hundredths of a second]>Used to specify that the procedure will be run in a Timer.
    This extension attribute is equivalent to TimerSys. Repetition is automatic. The optional value interval in hundredths of a second is used to specify the time interval between 2 repetitions:
    • If this value is not specified, it is necessary to specify the time interval between 2 repetitions using <interval>.
    • If this value is not specified, the values of <delay> and <interval> are initialized with the value of the specified interval.
    This extension attribute is not compatible with <thread> and <main thread>.

    Additionally, you can see the help about Automatic procedures.
  • extension attribute to manage threads:
    <thread>Used to specify that the procedure will be run in a secondary thread. For more details on threads, see Principle for running threads.

    This extension attribute is not compatible with <timer> and <main thread>.

    Additionally, you can see the help about Automatic procedures.
    <main thread>Used to specify that the procedure will be executed in the main thread. For more details on threads, see Principle for running threads.

    This extension attribute is not compatible with <timer> and <thread>.

    Additionally, you can see the help about Automatic procedures.
    <main thread asynchronous>Indicates that the procedure will be executed in the main thread and that there is no need to wait for the end of the execution of this procedure. For more details on threads, see Principle for running threads.

    This extension attribute is not compatible with <timer> and <thread>.

    Additionally, you can see the help about Automatic procedures.
    <secure thread>Used to specify that the procedure will be run in a secure secondary thread. For more details on threads, see Principle for running threads.

    This extension attribute is not compatible with <timer>, <main thread> and <UI>.

    Additionally, you can see the help about Automatic procedures.
    <light HFSQL context>Triggers the immediate copy of a part of the current HFSQL context.
    Only the directories containing the data files in HFSQL Classic mode and/or the connections in HFSQL Client/Server mode are stored.

    This extension attribute must be used with <thread>. For more details on the management of threads, see the help about ThreadExecute.
    Additionally, you can see the help about Automatic procedures.
    <full HFSQL context>Triggers the immediate copy of the current HFSQL context.
    Recommended if the thread must take into account the current positions in the files and queries of caller context.

    This extension attribute must be used with <thread>. For more details on the management of threads, see the help about ThreadExecute.

    Additionally, you can see the help about Automatic procedures.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 07/03/2023

Send a report | Local help