Calling a method that passes (event)

Hello,

When a method is linked to a form object (e.g., a button) through the OnAction event, it passes (event) to the method (e.g., “doSomething(event)”).

If I call the same method via another method, rather than through the button click, I am writing “doSomething()”. It seems to work, but Servoy 6 seems unhappy about missing its argument – there is a warning. Is there some way to pass (event) when the call comes from another method? Or should the call from the button be sent on to a third method, which actually does the work?

Thanks,
Don (newbie :) )

H Don, perhaps the method where you are calling that second method has benn called with the JSEvent object and you can pass it as weel. Antway you could send

I hope this helps.

If you want to call a bit of business logic from code and also attach it to a button directly, the proper way would be having an event handler method that you attach to the button that in turn calls the method with the business logic. That method with business can then also be called directly from code.

This way, in the unlikely event of Servoy having to add extra parameters to an event or the case where you need to add extra parameters to the business logic method, things will not conflict with each other.

However, if you want to take the shortcut and attach the business logic method also directly to the button, I guess you can send in null for the event param when you call it from another method.

Paul

Another option is to make the argument optional by putting square brackets around it in the jsdoc:

[attachment=0]optional_argument.png[/attachment]

Thanks for the tips everyone!

Don

Joas:
Another option is to make the argument optional by putting square brackets around it in the jsdoc

SWEET TIP! Thanks, Joas!