Adobe COLDFUSION 9 Manual page 1177

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Creating and using objects
You use the cfobject tag or the CreateObject function to create a named instance of an object. You use other
ColdFusion tags, such as
cfset
Many of the techniques for creating and using objects apply to both COM and CORBA objects. The examples here
assume a sample object named "obj", and that the object has a property called "Property", and methods called
"Method1", "Method2", and "Method3".
Creating objects
You create, or instantiate (create a named instance of) an object in ColdFusion with the
function. The specific attributes or parameters that you use depend on the type of object you use, and
CreateObject
are described in detail in
"Creating and using COM
page 1184. The following examples use a
a CORBA object:
<cfobject type="COM" action="Create" name="obj" class="sample.MyObject">
obj = CreateObject("CORBA", "d:\temp\tester.ior", "IOR", "Visibroker")
ColdFusion releases any object created by
ColdFusion page execution.
Using properties
Use standard ColdFusion statements to access properties as follows:
1
To set a property, use a statement or
<cfset obj.property = "somevalue">
To get a property, use a statement or
2
<cfset value = obj.property>
As shown in this example, you do not use parentheses on the right side of the equation to get a property value.
Calling methods
Object methods usually take zero or more arguments. You send In arguments, whose values are not returned to the
caller by value. You send Out and In,Out arguments, whose values are returned to the caller, by reference. Arguments
sent by reference usually have their value changed by the object. Some methods have return values, while others do not.
Use the following techniques to call methods:
• If the method has no arguments, follow the method name with empty parentheses, as in the following
<cfset retVal = obj.Method1()>
• If the method has one or more arguments, place the arguments in parentheses, separated by commas, as in the
following example, which has one integer argument and one string argument:
<cfset x = 23>
<cfset retVal = obj.Method1(x, "a string literal")>
• If the method has reference (Out or In,Out) arguments, use double quotation marks (") around the name of the
variable you are using for these arguments, as shown for the variable x in the following example:
<cfset x = 23>
<cfset retVal = obj.Method2("x","a string literal")>
<cfoutput> #x#</cfoutput>
and
, to invoke the object properties and methods.
cfoutput
objects" on page 1174 and
tag to create a COM object and a
cfobject
or
cfobject
CreateObject
tag, such as the following:
cfset
tag, such as the following:
cfset
Last updated 8/5/2010
cfobject
"Creating CORBA
objects" on
CreateObject
, or returned by other objects, at the end of the
1172
tag or
function to create
tag:
cfset

Advertisement

Table of Contents
loading

Table of Contents