WLanguage By Reference and By Value

WinDev Add comments

WinDev procedure parameters are passed by reference as a default and this is great but can also cause some strange issues in your code if you are not careful.

There are a few ways to pass an object by value and one of my favourite is using the LOCAL statement when defining your parameters.

Here’s an example:

image

If you don’t define anything as LOCAL then you can also tell WLanguage that you are passing by value just by adding brackets around the object you are passing:

CalculateWinnerPrizeTotals((nWinnerID), xCost)

So the example above shows how you can tell the method you are passing nWinnerID by value and not by reference.

Bookmark and Share

3 Responses to “WLanguage By Reference and By Value”

  1. Jonatan Says:

    What kind of strange issues can cause parameters by reference?

  2. Jonathan (Funcoder) Says:

    Passing an object by reference is not an issue its part of how WLanguage works.

    So for example, your had a variable called nValue with the value 5 and you called a method passing that variable:

    nValue is int = 5

    TestMethod(nValue)

    In TestMethod you changed nValue to be 10 then the code would display a dialog with the value 10.

    nValue is int
    TestMethod(nValue)
    Info(nValue)

    If you setup your procedure to get the object by value then the result would have been 5 as the method does not change the object that was passed, it take a copy of the object.

  3. Jonatan Says:

    I get it! Thank you very much. I like your windev/webdev articles.
    Best regards.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in