User Guide
Invoking Component Objects 369
Invoking Component Objects
You use the cfobject tag to create an instance of an object. You use other
ColdFusion tags, such as
cfset and cfoutput, to invoke properties (attributes), and
methods (operations) on the object. An object created by
cfobject or returned by
other objects is implicitly released at the end of the ColdFusion page execution.
The examples in the following sections assume that the name attribute in the
cfobject tag specified the value “obj”, and that the object has a property called
“Property”, and methods called “Method1”, “Method2”, and “Method3”.
Using properties
Use the following coding practices to access properties.
To set a property:
<cfset obj.property = "somevalue">
To get a property:
<cfset value = obj.property>
Note that parentheses are not used on the right side of the equation for
property-gets.
Calling methods
Object methods usually take zero or more arguments. Arguments can be sent by
value ([in] arguments) or by reference ([out] and [in,out]). Arguments sent by
reference usually have their value changed by the object. Some methods return
values, while others may not.
Methods with no arguments:
<cfset retVal = obj.Method1()>
Note that parentheses are required for methods with no arguments.
Methods with one or more arguments:
<cfset x = 23>
<cfset retVal = obj.Method1(x, "a string literal")>
This method accepts one integer argument and one string argument.
Methods with reference arguments:
<cfset x = 23>
<cfset retVal = obj.Method2("x", "a string literal")>
<cfoutput> #x#</cfoutput>
Note the use of double-quotation marks (") to specify reference arguments. If the
object changes the value of "x", it now contains a value other than 23.