Agile Tortoise
Greg Pierce’s blog
Servoy snippet: form_exists, form_method_exists
Here's a couple of useful Servoy methods I've been using...
To test for the existence of a form, use the following in a method (mine is in a mod_at module and named 'mod_at_form_exists'):
JavaScript:
-
eval('forms.'+arguments[0]);
-
return forms[arguments[0]] ? true : false;
Note the "eval" call ensures that the form has been loaded.
To test for the existence of a method on a form, use the following (i also keep this in a module, 'mod_at_form_method_exists'):
JavaScript:
-
var frmName = arguments[0];
-
var methodName = arguments[1];
-
-
if( !globals.mod_at_form_exists(frmName) )
-
return false;
-
-
return utils.stringLeft( typeof( forms[frmName][methodName] ), 7 ) == 'functio' ? true : false;
Note the last line is a workaround for Servoy's editor not allowing the keyword "function" to appear in a method (even in a string literal).
I use these methods to support abstracting form event methods using naming conventions and globals. I plan to post about that soon.
August 13th, 2008 at 1:38 pm
Thanks Greg. This really helped me out. I’m trying to create a generic navigation bar for record navigating and new/delete record kinda stuff. This was the trick that allowed me to check for a specific newRec method on each calling form, and if it doesn’t exist, I use currentcontroller.newRecord() instead. This allows me to put the nav bar anywhere and then have either a generic newRecord() or a custom one on the form, all with no code changes to the nav bar.
Thanks!