PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WD8] variable by reference or value
[WD8] variable by reference or value
Débuté par Gerard van Woudenberg, 16 aoû. 2004 17:46 - 3 réponses
Posté le 16 août 2004 - 17:46
Dear programmers,
I know there was a posting on the subject passing variables by reference or value and how to manipultate this. Can someone please give me some hints.
Kind regards
Gerard van Woudenberg


Our homebase
Posté le 16 août 2004 - 18:17
Hi Gerard,
I know there was a posting on the subject passing variables by reference or
value and how to manipultate this. Can someone please give me some hints.


Some difference:
Procedure:

Procedure MyProc(i)
i++

By Reference (Address - WD default)

j is int = 1
MyProc(j)
Info(j) //-> = 2

By Value

j is int = 1
MyProc((j))
Info(j) //-> = 1

Peter
Posté le 16 août 2004 - 18:21
Hi Gerard,
Check Parameters->Procedure Parmeters in teh help file.
This explains all possibilities for passing and retrieving paremeters.
Here's an extract:
===========================================================================
Procedure / function parameter
============================================================================
Procedure parameter
============================================================================
You can pass parameters to a procedure. This page covers the following topics:
- parameter type.
- passing parameters.
- local parameters.
- optional parameters.
Reminder: The W-Language does not differentiate between procedures and functions. Procedures and functions are managed the same way.
Parameter type
============================================================================
Default parameter type
You don't have to specify the type of a parameter. By default the type of the variable passed as a parameter to the procedure is used in the procedure. For example:
Subscript is int
// Calling the MyProc procedure
MyProc(Subscript)
-- Declaring the MyProc procedure
PROCEDURE MyProc(Counter)
// Counter is an integer
Counter += 1
The same procedure can be used with different types of variables.
Forcing the type of a parameter
To force the type of a parameter use the following syntax:
PROCEDURE Procedure name(Parameter 1 is Type,...
Parameter 2 is Type,...
...,Parameter N is Type)
The type of the variable passed as a parameter (when calling a procedure) must be identical to the type described in the procedure declaration. If not, an error will be generated when compiling the project, window or report.
In the following example, the "Subscript" variable is not a real: an error will be generated when compiling the project, window or report.
Subscript is int = 7
// Calling the MyProc procedure
MyProc(Subscript)
-- Declaration of the MyProc procedure
PROCEDURE MyProc(Subscript is real)
...
Passing parameters
============================================================================
When calling a procedure the parameters can be:
passed by variable (by address).
If the parameter is modified by the procedure, it will be returned to the calling statement with its modified value. To pass a parameter to a procedure by variable use the following syntax:
Procedure name(Name of the variable passed as a parameter)
For example:
Subscript is int = 1
// Before the call to the procedure, Subscript value is 1
AddOne(Subscript)
// After the procedure call, Subscript value is 2
-- Declaring the procedure
PROCEDURE AddOne(Count)
Count += 1
passed by value.
If the parameter is modified by the procedure, it will be returned to the calling statement with an UNMODIFIED value. To pass a parameter to a procedure by value use the following syntax:
Procedure name((Name of the variable passed as a parameter))
For example:
Subscript is int = 1
// Before the call to the procedure, Subscript value is 1
AddOne((Subscript))
// After the procedure call, Subscript value is still 1
--Declaring the procedure
PROCEDURE AddOne(Count)
Count += 1
a control, a window or a report.
This object (control, window or report) is managed the same way as a "standard" object. To pass an object as a parameter to a procedure, use the following syntax:
Procedure name(Object)
For example:
// Calling the VisibleControl procedure
VisibleControl(AddressControl)
-- Declaring the procedure
PROCEDURE VisibleControl(AddressControl)
AddressControl..Visible = False
Notes:
- The keyword Myself enables you to work with the current control.
- The keyword MyWindow enables you to work with the current window.
- The keyword MyReport enables you to work with the current report.
Local parameter
============================================================================
Parameter local to a procedure
When declaring a procedure, the variables passed as parameters can become local to the procedure. To do so, just add the keyword LOCAL before the parameter. For example:
PROCEDURE MyProc(LOCAL Subscript,LOCAL Counter, Number)
If this parameter is modified inside the procedure, the parameter will be returned to the calling statement with an UNMODIFIED value.
Note: An array type variable or an object (class instance) cannot become local to a procedure.
Optional parameter
============================================================================
Some of the parameters passed to a procedure can be optional. When declaring a procedure, the optional parameters must be the last parameters described (to the right) and their default value must be preceded by an "=" sign:
PROCEDURE Procedure name(Required parameters,...
Optional parameter 1 = Value,
Optional parameter 2 = Value,...)
For example:
-- Declaring the procedure
PROCEDURE Draw(Line,Column,BkgdCol = iBlak, PencilCol = iLightYellow)
...
-- Procedure call statement
Draw(10,15)
If you want to retain the default value of an optional parameter use the "*" character when calling the procedure. For example:
-- Declaring the procedure
PROCEDURE Draw(Line,Column,BkgdCol = iBlak, PencilCol = iLightYellow)
...

-- Procedure call statement
Draw(10,15,*,iLightGreen)


http://members.chello.be/cr45693
Posté le 16 août 2004 - 18:34
Dear programmers,
I know there was a posting on the subject passing variables by reference or value and how to manipultate this. Can someone please give me some hints.
Kind regards
Gerard van Woudenberg