C/AL Question (Function parameter)

Stan09
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.
Thank you for your answer.
0
Comments
-
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.0 -
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 fntmyfunctionmessage(rec.getfilters);
if "rec" is NOT passed byvar, you'll get an empty message0 -
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!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions