Passing a reference to a method

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
jabdefiant
Posts: 2
Joined: Fri May 31, 2019 1:07 pm

Passing a reference to a method

Post by jabdefiant » Fri May 31, 2019 1:21 pm

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

MarkD
Posts: 626
Joined: Wed Dec 02, 2015 9:56 am

Re: Passing a reference to a method

Post by MarkD » Fri May 31, 2019 1:52 pm

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.

jabdefiant
Posts: 2
Joined: Fri May 31, 2019 1:07 pm

Re: Passing a reference to a method

Post by jabdefiant » Sat Jun 01, 2019 5:43 am

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

Post Reply