Hi all,
I have never used this in LANSA, but I have used this technique in PHP and JavaScript.
It's sometimes called an anonymous function, or a closure, or a callback.
Basically, I would like to be able to pass a piece of code or a reference to a piece of code into a reuseable component method. And have that code run by the reusable component (maybe many times).
Does anyone know if this is possible in VL?
Regards
Andy
Passing a reference to a method
Re: Passing a reference to a method
Yes it is.
e.g
Mthroutine Name(SomeMethod)
Define_Map For(*INPUT) Class(#SomeOtherReusablePart) Name(#SomeOtherPartwithCode) Pass(*BY_REFERENCE)
#SomeOtherPartwithCode.Method1
#SomeOtherPartwithCode.Method2
Endroutine
Is that what you meant?
The trap is if you hang on to the reference across method calls, then you need to know when to set it back to *null to avoid potential resources leakage.
e.g
Mthroutine Name(SomeMethod)
Define_Map For(*INPUT) Class(#SomeOtherReusablePart) Name(#SomeOtherPartwithCode) Pass(*BY_REFERENCE)
#SomeOtherPartwithCode.Method1
#SomeOtherPartwithCode.Method2
Endroutine
Is that what you meant?
The trap is if you hang on to the reference across method calls, then you need to know when to set it back to *null to avoid potential resources leakage.
-
jabdefiant
- Posts: 16
- Joined: Fri May 31, 2019 1:07 pm
Re: Passing a reference to a method
Mark,
Thank you for the response. I think that's what I am looking for.
i am going to have to play with it a bit next week, and see if it does what I need.
Regards,
Andy
Thank you for the response. I think that's what I am looking for.
i am going to have to play with it a bit next week, and see if it does what I need.
Regards,
Andy