PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Principle
  • Declaring and calling internal procedures
  • Example
  • Characteristics of internal procedures
  • Use in callback
  • Internal Procedure parameter
  • Access to the variables from an internal procedure
  • Nesting internal procedures
  • Sibling internal procedures
  • Recursive calls
  • Named parameters
  • Dynamic compilation
  • Special case: Using internal procedures with asynchronous functions
  • Limitations
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Principle
Several features require a procedure called once or several times via a WLanguage function (also called "Callback"). For example, this is the case for the following functions: fListFile, TreeListItem, AlbumPicker in iOS, ...
A procedure must be created for these functions but several drawbacks appear:
  • Loss of code locality: The final algorithm cannot be entirely displayed. Several backs and forths must be performed between the calling code and the WLanguage procedure.
  • Difficulty to share information wiht the WLanguage procedure: In most cases, global variables must be used (to pass parameters to the callback or to retrieve the results).
In this case, the internal procedures are used to simplify the writing of callback features and to fix the problems caused when using a standard procedure.
Versions 21 and later
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
Android This feature is available for Android applications.
Android Widget This feature is available in Android Widget mode.
Java This feature is available for the Java applications.
New in version 21
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
Android This feature is available for Android applications.
Android Widget This feature is available in Android Widget mode.
Java This feature is available for the Java applications.
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
Android This feature is available for Android applications.
Android Widget This feature is available in Android Widget mode.
Java This feature is available for the Java applications.
Declaring and calling internal procedures
An internal procedure is declared in the code of an existing process (process associated with a control, window procedure, global procedure or class method, ...).
The syntax is as follows:
INTERNAL PROCEDURE <Procedure name>()
<Procedure code>
END
Notes:
  • The internal procedures must be declared in the process where they are used.
  • Versions 23 and later
    The assisted input is enabled for the parameters: a tooltip specifying the expected parameter type is displayed when typing the call to the internal procedure.
    New in version 23
    The assisted input is enabled for the parameters: a tooltip specifying the expected parameter type is displayed when typing the call to the internal procedure.
    The assisted input is enabled for the parameters: a tooltip specifying the expected parameter type is displayed when typing the call to the internal procedure.
  • The code of process found before and after the declaration code of internal procedure is run in sequence: the code of internal procedure is not run.
    Example:
    // Code before the internal procedure: This code is run.
    INTERNAL PROCEDURE MyInternalProcedure()
    // Code of the internal procedure.
    // This code is not run.
    END
    // Code after the internal procedure: This code is run.
  • An internal procedure can be directly called by its name, like any standard procedure. This call can be placed before or after the declaration of internal procedure.
    Example:
    // Call placed before
    MyInternalProcedure()

    // Declare the internal procedure
    INTERNAL PROCEDURE MyInternalProcedure()
    // Code of the internal procedure run during the call to MyInternalProcedure()
    END

    // Call placed after
    MyInternalProcedure()

    This allows you to get a code that is easy to read.
  • The exceptions triggered by the internal procedures can be processed outside the internal procedure.
WINDEVWEBDEV - Server codeWindows Mobile

Example

The following code is used to list all child elements of a node found in a TreeView control:
// List the "children" of the "Desserts" node in the "TREE_RecipeTV" TreeView
// The "ExpandAll" procedure is called
// for each "child" element found in the "Desserts" node
Res = TreeListItem(TREE_RecipeTV, "Recipes" + TAB + "Desserts", ExpandAll)
 
 
INTERNAL PROCEDURE ExpandAll(TREE_RecipeTV, ChildPath, ChildFound, Level, Pointer)
// Is the element found a leaf?
IF TreeTypeItem(TREE_RecipeTV, ChildPath + ChildFound) = tvLeaf THEN
RETURN // Go back to the TreeListItem function
ELSE
// Is the element found collapsed?
IF TreeStatus(TREE_RecipeTV, ChildPath + ChildFound) = tvCollapse THEN
TreeExpand(TREE_RecipeTV, ChildPath + ChildFound)
END
END
// Collapse the TreeView Table control
TreeCollapse(TREE_RecipeTV, "Recipes")
END
Characteristics of internal procedures

Use in callback

The internal procedure can be used in a WLanguage functions that expects a WLanguage procedure in parameter (like fListFile, TreeListItem, ...).
Caution: In this case, the parameter corresponding to the name of internal procedure must directly correspond to the name of internal procedure (the procedure name must not be enclosed in quotes).
Not to do:
// List the "children" of the "Desserts" node in the "TREE_RecipeTV" TreeView
Res = TreeListItem(TREE_RecipeTV, "Recipes" + TAB + "Desserts", "ExpandAll")
 
INTERNAL PROCEDURE ExpandAll(TREE_RecipeTV, ChildPath, ChildFound, Level, Pointer)
...
END
Do:
// List the "children" of the "Desserts" node in the "TREE_RecipeTV" TreeView
Res = TreeListItem(TREE_RecipeTV, "Recipes" + TAB + "Desserts", ExpandAll)
 
INTERNAL PROCEDURE ExpandAll(TREE_RecipeTV, ChildPath, ChildFound, Level, Pointer)
...
END

Internal Procedure parameter

The internal procedure can be used as parameter in a procedure. In this case, the parameter type will be "Procedure".
Example:
// Declare the internal procedure
INTERNAL PROCEDURE MyInternalProcedure()
// code run during the call to the procedure passed in parameter
END

MyOtherProcedure (MyInternalProcedure)
PROCEDURE MyOtherProcedure(p is Procedure)

p()
AndroidAndroid Widget Java This feature is not available.

Access to the variables from an internal procedure

The variables declared in the same process as the declaration of internal procedure can be called in the internal procedure. There is no need to use global variables anymore. This concept is called "Closure".
Example:
sElementList is string
sSeparator is string = CR
TreeListItem(TREE_TreeeViewControl, "", MyInternalProcedure)

INTERNAL PROCEDURE MyInternalProcedure(TreeViewName, Branch)
sElementList += [sSeparator] + Branch
END

Nesting internal procedures

The internal procedures can be nested. Each internal procedure can access the variables of procedures that include it.
Example:
ExternalVariable is int
Trace(ExternalVariable)
MyInternalProcedure1()
INTERNAL PROCEDURE MyInternalProcedure1()
InternalVariable1 is int
Trace(ExternalVariable + InternalVariable1)
MyInternalProcedure2()
INTERNAL PROCEDURE MyInternalProcedure2()
InternalVariable2 is int
Trace(ExternalVariable + InternalVariable1 + InternalVariable2)
END
END
Versions 23 and later

Sibling internal procedures

Two internal procedures found in the same procedure can be called between themselves (sibling internal procedures).
Example:
INTERNAL PROCÉDURE MyMainProcedure()

INTERNAL PROCÉDURE MyInternalProcedure1()
...
END

INTERNAL PROCÉDURE MyInternalProcedure2()
...
// Call the sibling procedure
MyInternalProcedure1()
END
END
New in version 23

Sibling internal procedures

Two internal procedures found in the same procedure can be called between themselves (sibling internal procedures).
Example:
INTERNAL PROCÉDURE MyMainProcedure()

INTERNAL PROCÉDURE MyInternalProcedure1()
...
END

INTERNAL PROCÉDURE MyInternalProcedure2()
...
// Call the sibling procedure
MyInternalProcedure1()
END
END

Sibling internal procedures

Two internal procedures found in the same procedure can be called between themselves (sibling internal procedures).
Example:
INTERNAL PROCÉDURE MyMainProcedure()

INTERNAL PROCÉDURE MyInternalProcedure1()
...
END

INTERNAL PROCÉDURE MyInternalProcedure2()
...
// Call the sibling procedure
MyInternalProcedure1()
END
END
Versions 23 and later

Recursive calls

An internal procedure can be called itself in recursive way.
New in version 23

Recursive calls

An internal procedure can be called itself in recursive way.

Recursive calls

An internal procedure can be called itself in recursive way.
Versions 23 and later

Named parameters

If an internal procedure includes parameters with default values, you have the ability to call the internal procedure by naming its parameters. Two syntaxes are possible:
  • Single-line named parameters,
  • Multiline named parameters.
See Named parameters in a procedure for more details.
New in version 23

Named parameters

If an internal procedure includes parameters with default values, you have the ability to call the internal procedure by naming its parameters. Two syntaxes are possible:
  • Single-line named parameters,
  • Multiline named parameters.
See Named parameters in a procedure for more details.

Named parameters

If an internal procedure includes parameters with default values, you have the ability to call the internal procedure by naming its parameters. Two syntaxes are possible:
  • Single-line named parameters,
  • Multiline named parameters.
See Named parameters in a procedure for more details.
Versions 24 and later

Dynamic compilation

You can use an internal procedure in a dynamically compiled code (with Compile, for example).
Example:
lsCode est string = [
// Code compiled dynamically
sElementList is string
sSeparator is string = CR
TreeListItem(TREE_TreeeViewControl, "", MyInternalProcedure)
 
INTERNAL PROCEDURE MyInternalProcedure(TreeViewName, Branch)
sElementList += [sSeparator] + Branch
END
 
]
 
lsResult is string
 
lsResult = Compile("MyProc",lsCode)
New in version 24

Dynamic compilation

You can use an internal procedure in a dynamically compiled code (with Compile, for example).
Example:
lsCode est string = [
// Code compiled dynamically
sElementList is string
sSeparator is string = CR
TreeListItem(TREE_TreeeViewControl, "", MyInternalProcedure)
 
INTERNAL PROCEDURE MyInternalProcedure(TreeViewName, Branch)
sElementList += [sSeparator] + Branch
END
 
]
 
lsResult is string
 
lsResult = Compile("MyProc",lsCode)

Dynamic compilation

You can use an internal procedure in a dynamically compiled code (with Compile, for example).
Example:
lsCode est string = [
// Code compiled dynamically
sElementList is string
sSeparator is string = CR
TreeListItem(TREE_TreeeViewControl, "", MyInternalProcedure)
 
INTERNAL PROCEDURE MyInternalProcedure(TreeViewName, Branch)
sElementList += [sSeparator] + Branch
END
 
]
 
lsResult is string
 
lsResult = Compile("MyProc",lsCode)
Special case: Using internal procedures with asynchronous functions
The internal procedures can be used as "Callback" for asynchronous functions.
CAUTION: In this case, the code found after the call to the function that is using an asynchronous WLanguage procedure will be run BEFORE the code of internal procedure.
Example: In this example for Windows Mobile, the code found after AlbumPicker will be run BEFORE the internal procedure. The internal procedure will be called when the picker is validated by the user.
AlbumPicker(albumImage, PhotoSelection)
INTERNAL PROCÉDURE PhotoSelection(sImagePath)
IMG_ImageControl = sImagePath
END
// Code run after the AlbumPicker function but
// BEFORE the code of internal procedure.
Limitations
  • An internal procedure cannot be named like the procedures that contain it.
  • Two internal procedures of same level cannot have the same name, even if they are declared in different code blocks (IF THEN ELSE, ...).
  • The internal procedures are not available in dynamic compilation.
  • The execution of an internal procedure cannot be automated.
  • The automatic management of errors is not available for the internal procedures.
  • A process or an internal procedure can only call its direct internal procedures. In particular, an internal procedure cannot call an internal procedure of same level.
Minimum version required
  • Version 20
This page is also available for…
Comments
Click [Add] to post a comment