|
|
|
|
|
- Overview
- Passing parameters to a window when it is opened
- Parameter passing: general case
- Parameters passed by value
- Giving a default value to the parameter in the declaration
- Named parameters
- Scope of parameters
- Returning a value when a window is closed
- Testing a window with parameters
A window can: - Receive parameters when it is opened.
- Return values when it is closed.
This window behaves like a procedure that may (or may not) return values. This type of window can be useful in the following cases: - "calendar" windows (fix a default date when it is opened and return a selected date when it is closed),
- search windows,
- login windows returning the password typed, ...
This help page presents: Passing parameters to a window when it is opened Parameter passing: general case To pass parameters to a window when it is opened: - Declare a procedure in the "Global declarations" event of the window. The name of this procedure is the same as the window name. The parameters of this procedure correspond to the parameters that must be passed to the window.
Warning: The procedure declaration (PROCEDURE keyword) must correspond to the first line of the "Global declarations" event.. For example, the WIN_CALENDAR window is used to manage the date selection in a calendar. This window expects a parameter indicating the date to select.
PROCEDURE WIN_Calendar (sSelDate)
This parameter can be handled from any event of the window (button, local procedures, etc.). For example, in the "Initialization" event of WIN_Calendar:
// -- Initializing WIN_Calendar  // EDT_DateControl is an edit control // It contains the value of the sSelDate parameter EDT_DateControl = sSelDate
- Pass the parameter expected by the window (Open, OpenMobileWindow, OpenChild, OpenSister, MDIOpen). For example, the BTN_Calendar button is used to open the WIN_Calendar window. Today's date is passed as parameter when this window is opened.
// -- Click code of BTN_Calendar  // Open the WIN_Calendar window // Today's date is passed as parameter Open(WIN_Calendar, Today())
Parameters passed by value If the parameters passed to a window are modified in this window, these modifications will be taken into account in this window only. The value of these parameters is not modified in the calling process. For example: - The MyDate variable is declared in the code of the BTN_Calendar button. This variable contains today's date (for example: MyDate = Today()).
- This variable is passed as a parameter to WIN_Calendar. The parameter sDateSel contains the value of the variable MaDate.
- The value of parameter sDateSel is modified in the FEN_Calendar window (for example: sDateSel = "20020701").
- The value of the MyDate variable is not modified.
Giving a default value to the parameter in the declaration A default value can be given to the parameters when declaring the parameters. In this case, the parameter becomes optional. If it is omitted, the default value will be used. For example, to give a default value in the previous example, enter the following code in the "Global declarations" event of WIN_Calendar:
PROCEDURE WIN_Calendar(sSelDate = "20030101")
Named parameters You can also pass named parameters to a window when it is opened: - Declare the procedure as usual. Example:
PROCÉDURE WIN_Travel(Identifier, Availability)
- Pass the parameter expected by the window when it opens (functions Open, OpenMobileWindow, OpenChild, OpenSister, MDIOpen) using the syntax:
<Nom du paramètre>: Value For example: Open(WIN_Travel(<Identifier>:123456, <Availability>:True))
Note: Named parameters can be used, for example, to change the order of expected parameters.. For example, you can write: Open(WIN_Travel(<Availability>:True, <Identifier>:123456))
Scope of parameters The parameters passed to a window are global to all the events of this window (initialization, code of a button, code of a local procedure, etc.). Returning a value when a window is closed To return a value when a window is closed: - Use ReturnedValue in the processes that call Close.
For example, in the WIN_Calendar window, the BTN_OK button and the BTN_CANCEL button close the window once the value to return was initialized:
// -- Click BTN_OK (WIN_Calendar window) Â // OK was clicked by the user, // the date entered in the EDT_DateControl control is returned MyWindow.ReturnedValue = EDT_DateControl // Close the window Close()
// -- Click BTN_CANCEL (WIN_Calendar window) Â // The BTN_CANCEL button was clicked by the user, // an empty string is returned MyWindow.ReturnedValue = "" // Close the window Close()
You can also use the ReturnedValue property in the "Close" event of the window:
// -- Closing code of WIN_Calendar window  // The date is entered in the EDT_DateControl control IF EDT_DateControl = "" THEN // No date was entered MyWindow.ReturnedValue = "" ELSE // A date is entered MyWindow.ReturnedValue = EDT_DateControl END
- Retrieve in a variable the value returned by the window when it was closed. This variable contains the result of Open.
For example, the BTN_Calendar button is used to open the WIN_Calendar window. When opening this window (Open), today's date is passed as parameter. The value returned by the window when it is closed corresponds to the result returned by Open. This result is retrieved in the ResultDate variable:
ResultDate = Open(WIN_Calendar, Today())
IF ResultDate = "" THEN
Info("No date was selected.")
ELSE
Info("Selected date: " + DateToString(ResultDate, maskSystemDate))
END
The code execution of BTN_Calendar is stopped until the WIN_Calendar window is closed. Testing a window with parameters To run the test of a window with parameters: - Open the parameterized window in the window editor: in the "Home" pane, in the "General" group, click on "Open".
- Click in the quick access buttons (or press F9). The following window is displayed:
- Specify the value of the parameters that will be used to test the window. To use the default value of the parameters, type the "*" character.
- Validate. The window is displayed according to the specified values.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|