Adobe COLDFUSION 9 Manual page 1181

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
<!--- First, create the object --->
<cfobject type="COM"
action="Create"
name="Mailer"
class="CDONTS.NewMail">
<!--- Second, use the form variables from the user entry form to populate a number
of properties necessary to create and send the message. --->
<cfset Mailer.From = "#Form.fromName#">
<cfset Mailer.To = "#Form.to#">
<cfset Mailer.Subject = "#Form.subject#">
<cfset Mailer.Importance = 2>
<cfset Mailer.Body = "#Form.body#">
<cfset Mailer.Cc = "#Form.cc#">
<!--- Last, use the Send() method to send the message.
Invoking the Send() method destroys the object.--->
<cfset Mailer.Send()>
Note: Use the
and
cftry
cfcatch
handling, see
"Handling runtime exceptions with ColdFusion
Releasing COM objects
By default, COM object resources are released when the Java garbage collector cleans them. You can use the
function to immediately release resources if an object is no longer needed.
ReleaseCOMObject
Use the
ReleaseCOMObject
Microsoft Excel. The garbage collector does not always clean these processes in a short time, resulting in multiple
external processes running, which drains system resources.
If the COM object has an end method, such as a quit method that terminates the program, call this method before you
call the
ReleaseComObject
is prematurely released and your application gets exceptions.
Example
The following example creates a Microsoft Excel application object, uses it, then releases the object when it is no longer
needed:
<h3>ReleaseComObject Example</h3>
<cfscript>
obj = CreateObject("Com", "excel.application.9");
//code that uses the object goes here
obj.quit();
ReleaseComObject(obj);
</cfscript>
General COM object considerations
When you use COM objects, consider the following to prevent and resolve errors:
• Ensuring correct threading
• Using input and output arguments
• Understanding common COM-related error messages
tags to handle exceptions thrown by COM objects. For more information on exception
function to release COM objects that are launched as an external process, such as
function. If you use the
ReleaseComObject
Last updated 8/5/2010
tags" on page 287.
function on an object that is in use, the object
1176

Advertisement

Table of Contents
loading

Table of Contents