Using COM


The Component Object Model (COM) is a Microsoft specification that enables you to implement component modules in a program. COM objects can be written in many languages; as long as each language understands COM, it can understand any COM object, even if it is written in another language.

The fact that COM objects can be written in many languages gives them an immediate advantage over the CFX custom tags. Whereas CFX custom tags are written specifically for use in the ColdFusion environment, COM objects can be used across many applications.

NOTE

COM is only supported on Windows platforms.


TIP

Before you call a COM object from within ColdFusion code, you must first register it with the system. Most objects come with instructions on how to do this.


To call a COM object in ColdFusion, type the following:

 <cfobject type="COM"                      name="objCompany"           action="Create"> 

This example creates a Company object and then populates it with properties such as the following:

 <cfset objCompany.company_name="Macromedia"> <cfset objCompany.for_profit="1"> <cfset objCompany.revenues="85000323.56"> 

The following code then creates a department and populates it with an array of employees:

 <cfset objDoc=objCompany.CreateDepartment('Documentation')> <cfset doc_employees=ArrayNew(1)> <cfset doc_employees[1]="MetMaker, Baldy"> <cfset doc_employees[2]="HealthFood, Donuts"> <cfset doc_employees[3]="Mellow, Fellow"> <cfset objDoc.AddEmployees(doc_employees)> 

Arrays are discussed in Chapter 14, "Arrays."


The information that you have entered into the object can be used within a ColdFusion page as follows:

 <cfoutput>  Company Name: #objCompany.company_name#<br>  For Profit: #objCompany.for_profit#<br>  Revenues: #objCompany.revenues#<br>  Departments: #objCompany.department_count#<br> </cfoutput> <cfset Revenue=objCompany.revenue> <cfset Revenue.Q1="22124345.83"> <cfset Revenue.Q2="18536444.02"> 

This code first assigns the objCompany.revenue object to the ColdFusion local variable Revenue, and then assigns quarterly earnings to it.

NOTE

As ColdFusion runs on underlying Java technology and in a JVM (Java Virtual Machine), support for COM is never native, even on Windows. Rather, the COM requests are handled by an external interface to which requests are routed. This has performance implications, and so the use of Java extensions is preferable.




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net