Hi Friends,
in AX, there is no ref parameter like other language, what's alternative then? If I need to pass something to method, and get updated value back.
Thanks,
*This post is locked for comments
Hi Friends,
in AX, there is no ref parameter like other language, what's alternative then? If I need to pass something to method, and get updated value back.
Thanks,
*This post is locked for comments
Strictly speaking, everything in X is passed by value; it doesn't support passing by reference (with the exception of .NET Interop).
I guess you're interested in how table buffer behaves and you just got confused by the whole "by reference" thing. Although everything it passed by value, it makes a huge difference if you pass a value type or a reference type.
If you pass an object reference, you refer to the same object, but it doesn't mean that the reference itself wasn't passed by value. Here "a reference" and "by reference" means two different things. One means that the value is just a reference to the object heap, while the latter means that you would get a pointer to the value and not the value itself.
Tables are reference types, therefore although references are passed by values, they point to the same object and you can change the same object from any place (where you have the reference). For example, the following code will display "Changed":
public void run() { CustGroup cg; cg.CustGroup = 'Original'; this.changeBuffer(cg); info(cg.CustGroup); } void changeBuffer(CustGroup _cg) { _cg.CustGroup = 'Changed'; }
When I pass a table buffer , is it passed by values or by reference as per my test it seems it is passed by values by I need to confirm my conclusion ?
X++ is not able to pass value types by reference, because it doesn't support it. Although it may simplify some cases, it's never necessary, therefore you should change your design to something that makes sense in X++.
By the way it has nothing to do with object-oriented programming. On the contrary, it was important for structured languages such as C and it's not needed in object-oriented programs anymore, because you can use... objects.
Hi Hariharan,
Passing parameter by ref is so common in other OOLs, in my case, just want get a simple record count back from method.
For whatever reason, X++ is not able to pass reference. Thanks everybody's input. I know what to do next.
You can use the X++ keyword byref to call .NET methods that take parameters by reference.
In all X++ methods, all parameters are passed by value. In .NET, parameters can be passed by value or by reference.
You must understand the parameter passing concepts of by value versus by reference before you can correctly use the byref keyword.
If you want to return a single value you can simply return a value by using function.
If you want to pass the parameter by reference, x++ is not supported, you can use .Net methods by calling from x++.
Could you please explain me that why you want to pass the parameter by reference?
Please refer this link msdn.microsoft.com/.../cc586700.aspx
If you "want to return a simple integer from method", just return the integer at the return value, as Bhaskar Roy suggested.
If you want to return a reference, use a reference type, as I suggested. Whether you consider it as a overkill or not is irrelevant.
Boxing/unboxing wouldn't help you in any way.
could I get more inside end to end.
Hi Bhaskar,
This is not what I want. Just need to pass parameter.
It is very simple please create your method return type integer and return the value. I don't know, I am missing anything or not.
Hi Martin,
I just want to return a simple integer from method, using class seems to me is overkill.
Also, as others said, using Container to do it, is this something like boxing/unboxing in X+?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156