The difference between pass-by-reference and pass-by-value is that modifications made to arguments passed in by reference in the called function have effect in the calling function, whereas modifications made to arguments passed in by value in the called function cannot affect the calling function.
And it’s like that in any programing language, right? Well, no not in every case with Businesses Central AL, using a Variant Data Type and Record Ref’s have a little bug. Let’s check it out.
Let’s define a RecRef and assign it to a Sales Line table for example and create a function that accepts input parameter Passed by value of type Variant, you can also try with RecordRef.
And in documentation it is stated that “If one RecordRef variable is assigned to another RecordRef variable, then they both refer to the same table instance.” But why it is changing pass as value to pass as reference?
So, the best, practice: “you should Close the record ref before changing the assignment to another table”. And if you do that the problem will be solved. Nevertheless, this does not change the fact that the Parameter pass-by-value acts like a pass-by-reference, which should never happen, in any case!
Please also note that this is an isolated example problem originated when I was using standard Codeunit Data Type Management.
It should be like this:
Additionally, I have reported an issue to Microsoft you can track the issue on link below, until than be sure to Close RecordRef before assignment to other Record to avoid the problem.
Comments
Post a Comment