
256
Chapter 13 Extending ColdFusion Pages with CFML Scripting
function makes using the structure appears, but the change the function makes
using the directly passed array does not affect the array outside the function.
<CFScript>
//Create a two-element array inside a structure
mystruct = StructNew();
mystruct.myarray = ArrayNew(1);;
mystruct.myarray[1] = "This is the original element one";
mystruct.myarray[2] = "This is the original element two";
//Define a custom function to manipulate both
//an array in a structure (using struct_param) and
//an array that is passed directly (using array_param).
function setarray( struct_param, array_param )
{
//Change the first element of the array passed in the structure
struct_param.myarray[1] = "This is the NEW element one";
//Change the seond element of the directly-passed array
array_param[2] = "This is the NEW element two";
return "success";
}
//Call the function passing the structure and the array
setarray( mystruct, mystruct.myarray);
</CFScript>
<CFOutput>
<!--- The element one is changed --->
<br>#mystruct.myarray[1]#
<!--- Element two is unchanged because the function got a copy --->
<br>#mystruct.myarray[2]#
</CFoutput>
Error handling
You can handle errors in custom functions by writing a status variable indicating
success or failure and some information about the failure. You can also return a
special value to indicate failure. The following sketch outlines possible combinations
of both these approaches:
function bigCalc(x, y, errorInfo)
{
// Clear error state
// This allows errorInfo struct to be reused
structClear(errorInfo);
var isOK = true;
// Do work, populate fields in errorInfo such as
// errorNumber, errorMsg, errorDetail, whatever
...
if (isOK)
{
return calculatedValue;
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...