Warning! explation required.

Questions, tips and tricks and techniques for scripting in Servoy

Warning! explation required.

Postby 4xjbh » Sun Jul 11, 2010 6:56 am

I have this warning in the developer and not sure what to do.

Event parameter(s) is passed to the event method, make sure it is used with the right type (change method signature)


It is related to part of a file upload method, the lines below have the warning markers.

Code: Select all
var v_documentsid = arguments[0];
var v_version_number = arguments[1];
Regards,

James
4xjbh
 
Posts: 146
Joined: Fri Feb 24, 2006 8:06 am
Location: Brisbane, Australia

Re: Warning! explation required.

Postby ptalbot » Sun Jul 11, 2010 8:58 am

With Servoy 5.1, you need to name the parameters in the method signature, so instead of doing this:
Code: Select all
function uploadMethod() {
    var v_documentsid = arguments[0];
    var v_version_number = arguments[1];
    // do your stuff
}


you should write it this way:
Code: Select all
function uploadMethod(v_documentsid, v_version_number ) {
    // do your stuff
}


This is much cleaner, concise and less error prone, it will help reading your methods, and you can also add jsdocs to the header of your methods this way:
Code: Select all
/**
* This method does some stuff...
*
* @param (Integer) v_documentsid the id of the document which represent this or that...
* @param (String) v_version_number the version number, used to do that or the other...
* @return something
*/
function uploadMethod(v_documentsid, v_version_number ) {
    // do your stuff
}


Then you will benefit from code completion everywhere in Servoy, and when you type yourForm.uploadMethod, it will show you your comments and the parameters that are to be passed to the method.
And you can even generate html documentation out of it (see my JSDocPlugin for this)!

Hope this clarifies,
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Warning! explation required.

Postby 4xjbh » Sun Jul 11, 2010 10:01 am

Thanks Patrick.
Regards,

James
4xjbh
 
Posts: 146
Joined: Fri Feb 24, 2006 8:06 am
Location: Brisbane, Australia

Re: Warning! explation required.

Postby jcompagner » Mon Jul 12, 2010 11:50 am

that warning has 1 extra thing, if you do this:

Code: Select all
function uploadMethod() {
    var v_documentsid = arguments[0];
    var v_version_number = arguments[1];
    // do your stuff
}


that means that you should now do this:

Code: Select all
function uploadMethod(event, v_documentsid, v_version_number) {
    // do your stuff
}


because this is a function that is attached to a ui elements event. So servoy will now give you a JSEvent parameter with some info about the call.
in other words: arguments[0] != always what you expect (that v_documentsid) !!
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Methods

Who is online

Users browsing this forum: No registered users and 7 guests