C/AL Question (Function parameter)

Stan09Stan09 Member Posts: 63
For a function, what is the difference between a record parameter passed by reference and one passed by "value".
Thank you for your answer.

Comments

  • matttraxmatttrax Member Posts: 2,309
    The same as for any variable passed by reference or value.

    When you pass by reference the actual variable that you use as a parameter gets changed. So the actual variable and the parameter variable point to the same place in memory. Sort of like a global variable...sort of.

    When you pass by value, a copy of the variable is made and passed to the function. Since it's a copy they point to different places in memory and a change to one does not affect the other.

    Reference Example:

    Func Add(int a, int b, ref int result)
    result := a + b;

    Add(1, 2, myResult);

    The value of myResult after the above line is executed will be 3. If it had been passed by value, it would still have the same value as before the add function is called.

    There is no difference between a simple variable and a record variable.
  • BeliasBelias Member Posts: 2,998
    Another thing to point out about records:
    if var is not checked, you don't pass record filters that have been set on your variable.
    e.g.:
    rec.setfilter(field1,'a');
    fntmyfunction(rec)
    

    now here's fntmyfunction
    message(rec.getfilters);
    
    if "rec" is NOT passed byvar, you'll get an empty message
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • garakgarak Member Posts: 3,263
    Did you take a look into the Developers Guide before?

    I ask, because a question like this is an exam questions ....
    Do you make it right, it works too!
Sign In or Register to comment.