Parameters are named data values with a specified data type used as input values for functions and event handlers.
A parameter is a named area of device memory containing a value of a specified type.
In UJML, a parameter is declared like a variable; using a var element inside of a parameters element. See var, parameters, Variables. Parameters must have valid names and data types. See Identifiers, Data Types. Parameters are used like variables; you can use them in expressions, pass them to functions, and assign values to them.
Unlike variables, a parameter may not be an array. See Arrays. Therefore, a var element inside of a parameters element cannot contain a size attribute.
Parameter scope is limited to the function or event handler declaring the parameter. See Data Scoping and Sharing. Therefore, a var element inside of a parameters element cannot contain an access attribute.
Parameters are declared and used in functions as a way to pass data to the function when it is called. See User Defined Functions. The calling code specifies the parameter values in the same order as they are declared in the function, using either variables or literals for the values. See Literals and Constants, Variables.
UJML component interfacess can define events with parameters. See Component Events. Event handlers which catch these events must define the same parameters in the same order as they are defined for the component event.
When a function is called or an event is fired, UJML creates a copy of the data being passed and puts that copy into the function or event parameters. This means you can assign a value to a parameter, just as you would to a variable, within the local scope of the function or event and only affect the value within the local scope. For example, if code calling a function passes a variable to a parameter that variable remains unaffected. See the sample assignment.ujml for an example of this behavior.
To illustrate this further, let us consider a scenario where we have code with a local variable called 'foo' calling a function with a parameter called 'bar' and passing the value of 'foo' to the parameter 'bar'. The code for this scenario looks like:
<ujml>
<application>
<variables>
<var name="foo" type="int"/>
</variables>
<functions>
<function name="double" type="void">
<parameters>
<var name="bar" type="int"/>
</parameters>
<script>
bar = bar * 2;
</script>
</function>
</functions>
<script>
foo = 128;
double(foo);
</script>
</application>
</ujml>
The actions and results of running this code look like this:
|
Action |
Local Code |
Function Code |
Local variable 'foo' value |
Function parameter 'bar' value |
|
Assign a value to 'foo'. |
foo = 128; |
|
128 |
0 |
|
Call the function 'double'. |
double(foo); |
|
128 |
128 |
|
The function doubles the parameter value. |
|
bar = bar * 2; |
128 |
256 |
Note that 'bar' is zero until the function is called, at which time it is given a copy of the value in 'foo'. Then script inside the function changes the value of 'bar' without affecting 'foo'.
Like variables, parameters are not re-entrant, meaning that a function cannot call itself (a process called 'recursion') directly or indirectly. See User Defined Functions.
|
Copyright (c) 2000-2007 UIEvolution, Inc. All rights reserved.
|
|
What do you think about this topic? Send feedback!
|