Page 1 of 1

Passing a reference to a method

Posted: Fri May 31, 2019 1:21 pm
by jabdefiant
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

Re: Passing a reference to a method

Posted: Fri May 31, 2019 1:52 pm
by MarkD
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.

Re: Passing a reference to a method

Posted: Sat Jun 01, 2019 5:43 am
by jabdefiant
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