I was wrong saying the documentation is obsolete. It is just very incomplete and ambiguous.
Following the documentation, one's declare a Java script byThis works only if the array contains at least two different types. For instance :The java script receives args[0] with type "any", args[1] with type String et args[2] with type Double.
But the script will not be called if parameters have the same type.In that case, the macro must be declared with the right type :And the use of an array is not compulsory. One can use a unique parameter, but with the proper type (Object is not possible). For instance :can be called by :Passing numeric parametres that way is not really practical, for the ScriptManager doesn't consider the type delared by Dim, but only the real value of the data. That means that, if you change D = 12.5 by D = 12.0, the Script Manager will consider the data as a Byte, and the java macro will be called only if it declares the parameter by 'Byte args' (or 'Short args' or 'Long args' depending of the shortest bit number necessary to code the data). That means that the only secure way to transmit a numerical value is to put it in an array for an Objet[] parameter, and to cope with the different types received.
And last, it is possible to have as many parameters as desired in the Java prototype. For instancewhere all parameters must follow the above rules.
Following the documentation, one's declare a Java script by
Code:
public static String maMacro(XScriptContext xScriptContext, Object[] args)
Code:
Dim param1(2)param1(0)=thisComponent : param1(1)="un texte" : param1(2) = 12.5Dim params(0) : params(0) = param1result = script.invoke(params, outIndex, outParams)
But the script will not be called if parameters have the same type.
Code:
param1(0)="un texte": param1(1)="un deuxième texte" : param1(2) = "un troisième texte"]
Code:
public static String maMacro(XScriptContext xScriptContext, String[] args)
Code:
public static String maMacro(XScriptContext xScriptContext, Double args)
Code:
Dim D as Double : D = 12.5Dim params(0) : params(0) = Dresult = script.invoke(params, outIndex, outParams)
And last, it is possible to have as many parameters as desired in the Java prototype. For instance
Code:
public static String maMacro(XScriptContext xScriptContext, String[] args1, Object[] args2, String args3, ActionEvent args4)
Statistics: Posted by Cormic — Sat Aug 10, 2024 2:39 pm