Creating and using COM objects
769
<!--- 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
cftry
and
cfcatch
tags to handle exceptions thrown by COM objects. For more
information on exception handling, see
Chapter 14, “Handling runtime exceptions with ColdFusion
tags,” on page 299
.
Releasing COM objects
By default, COM object resources are released when the Java garbage collector cleans them. You
can use the
ReleaseCOMObject
function to immediately release resources if an object is no longer
needed.
Use the
ReleaseCOMObject
function to release COM objects that are launched as an external
process, such as Microsoft Excel. The garbage collector might not 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
function. If you use the
ReleaseComObject
function on an object that is in use, the object is prematurely released and your application will
get 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();
ReleaseObject(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
The following sections describe these issues.
Содержание ColdFusion MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...