Using Dynamic Evaluation - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

Dynamic variable limitation
When you use a dynamic variable name in quotes on the left side of an assignment, the name
must be either a simple variable name or a complex name that uses object.property notation (such
as MyStruct.#KeyName#). You cannot use an array as part of a dynamic variable name. For
example, the following code generates an error:
<cfset MyArray=ArrayNew(1)>
<cfset productClassNo = 1>
<cfset productItemNo = 9>
<cfset "myArray[#productClassNo##productItemNo#]" = "Widget">
However, you can construct an array index value dynamically from variables without using quotes
on the left side of an assignment. For example, the preceding sample code works if you replace the
final line with the following line:
<cfset myArray[#productClassNo# & #productItemNo#] = "Widget">
Dynamically constructing structure references
The ability to use associative array notation to reference structures provides a way for you to use
variables to dynamically create structure references. (For a description of associative array
notation, see
Chapter 5, "Structure notation," on page
allows you to use a ColdFusion expression inside the index brackets. For example, if you have a
productName structure with keys of the form product_1, product_2 and so on, you can use the
following code to display the value of productName.product_3:
<cfset prodNo = 3>
<cfoutput>
Product_3 Name: #ProductName["product_" & prodNo]#
<cfoutput>
For an example of using this format to manage a shopping cart, see
shopping cart" on page

Using dynamic evaluation

The following sections describe how to use dynamic evaluation and create dynamic expressions.
ColdFusion dynamic evaluation functions
The following table describes the functions that perform dynamic evaluation and are useful in
evaluating dynamic expressions:
Function
DE
Evaluate
94
Chapter 4: Using Expressions and Pound Signs
99.
Purpose
Escapes any double quotes in the argument and wraps the result in double
quotes. The
function is particularly useful with the
DE
function from evaluating a string to be output.
For an example of using the
function" on page
98.
Takes one or more string expressions and dynamically evaluates their contents
as expressions from left to right. (The results of an evaluation to the left can have
meaning in an expression to the right.) Returns the result of evaluating the
rightmost argument.
For more information on this function see
on page
95.
114.) Associative array structure notation
"Example: a dynamic
function with the
DE
IIF
"About the Evaluate function"
function, to prevent the
IIF
function, see
"Using the IIF

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents