Only in the designer can you attach a ethod to an event.
In the method, you can built logic though, to perform no, or different actions, based on certain variables (variables that you have to know, otherwise you wouldn’t be able at runtime when to add a method on whihc object under which circumstance)
So, if I use the servoy events. And if they can only be used from within the designer, I state that I cannot use an event in form A from form B. Which was what I was looking for.
Is this correct? So, Form B cannot be noticed when e.g. event onRecordSelection in Form A occurrs (Without calling a method in form A first, which then calls a method in form B)?
So, if I use the servoy events. And if they can only be used from within the designer, I state that I cannot use an event in form A from form B. Which was what I was looking for.
You define in Designmode which Method you attach to a certain event
Is this correct? So, Form B cannot be noticed when e.g. event onRecordSelection in Form A occurrs (Without calling a method in form A first, which then calls a method in form B)?
There are no event listeners between form. Period!
But, you can attach methods to Servoy events on objects and in those methods, you can code whatever you want (as allready described in previous post in this topic).
I’ve been a lurker for a while and I just want to say thanks to everyone on the forums. It’s been an invaluable resource.
Anyway, I was looking for a way to call a method by variable based name. I came across this topic thread. Based on the eval() in this thread I made a global method that will execute any method and return whatever that method returns. The methods can be global or local, doesn’t matter. I don’t know if this is helpful but here’s the code:
/*********************************************************************************
object: executeMethod
call: executeMethod(string methodName [string ,formName][string ,parameter])
does: executes method defined by methodName parameter
returns: whatever the called method returns
********************************************************************************/
var vMethodName = arguments[0];
var vFormName = arguments[1]; //if no form parameter, assumes global method
var vMethodParam = arguments[2]; //optional
var vMethodReturn;
// only execute if form is valid or there's no form parameter
// this prevents executing a global method when a local method with same name is intended
if (forms[vFormName] || !vFormName) {
if (vFormName) {
// local method
vMethodName = 'forms.' + vFormName + '.' + vMethodName;
}
else {
// global method
if (!(utils.stringLeft(vMethodName, 8) == 'globals.')) {
vMethodName = 'globals.' + vMethodName;
}
}
// if method exists, execute
if (eval(vMethodName)) {
// add parameters to eval string
if (vMethodParam) {
vMethodName += '(' + vMethodParam + ')';
} else {
vMethodName += '()';
}
// execute method
vMethodReturn = eval(vMethodName);
}
}
// output invalid method call to debugger
if (!vMethodReturn) {
var vError = 'invalid method call: ' + vMethodName;
application.output(vError);
}
return vMethodReturn;
Your solution finally looks like a way for me to go: The parent forms register there name and the method to call in a variable (global or local to the child form). The child only knows this variable (an array e.g.) and iterates over the items and calls all methods in parent forms. And I get my decoupling. Great! Thank you very much!
I did not yet give it a try. But by reading your code I assume you call (evaluate) the method vMethodName twice, right? Is there a way to avoid this? Like “doesMethodExist(vMethodName)” instead of eval(vMethodName)?
The method is only actually called once. When using eval without the ‘()’ on the end of the method name returns a boolean where adding the () actually executes the method. So that last bit just checks if the method is valid and if it is, it adds the (parameters) to the end and executes.
At least in my testing on this, that has been the case. If anyone on the forum can confirm this, I would appreciate it.