Check for attached event handler  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Check for attached event handler

Postby SBarnes » Tue Mar 23, 2021 1:43 pm

Is there a way to check if a specific handler has already been attached to an event namely the saveend on an inventory item?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Check for attached event handler  Topic is solved

Postby Mike.Sheen » Tue Mar 23, 2021 5:54 pm

SBarnes wrote:Is there a way to check if a specific handler has already been attached to an event namely the saveend on an inventory item?


Not outside the class that defines the event you can't.

Inside the Inventory class we could do something like this...

Code: Select all
Action[] handlers = Inventory.SaveEnd.GetInvocationList();


...but as an outsider you cannot do that - it won't even compile.

Perhaps there is another way to achieve what you need... why do you need to know if another handler has already subscribed to that event?
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Check for attached event handler

Postby SBarnes » Tue Mar 23, 2021 6:10 pm

Yes I figured out that GetInvocationList won't compile pretty quickly, what I am trying to do is create a save end and attach it to the inventory object used in the inventory import.

The problem is because you can't get the inventory object until one of my extra destination properties is called but you don't know left to right in the csv what will be first you need to attempt to add the handler in each extra property handler and I am not sure I won't end up with the same handler being called twice but I think I've thought of a work around, and that is try removing the handler first and then add it so that way you only end up with one.

I was just hoping to come up with a clever bit of code to work it out and learn something new into the bargain.

The other option I've thought of is just throw a true/false in in the inventory object's generic object list to say the handler is attached or not, basically my reason for adding the save end is so that I can pluck out my own business object from the generic object list and save the extra stuff that I am adding to the inventory import which is what some of the destination property handlers will be filling in.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 0 guests