User Guide Cancel

cfobject: component object

 

Description

Creates an instance of a ColdFusion component (CFC) object.

Syntax

<cfobject
component = "component name"
domain = "domain name"
name = "instance name"
password = "the password"
type = "component"
username = "the user name">
<cfobject component = "component name" domain = "domain name" name = "instance name" password = "the password" type = "component" username = "the user name">
<cfobject 
component = "component name" 
domain = "domain name"
name = "instance name"
password = "the password" 
type = "component"
username = "the user name">
Note:

You can specify this tag's attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag's attribute names as structure keys.

History

ColdFusion (2016 release) Update 3: Added the attributes domain, username, and password.

Note: The new attributes are applicable only when type="COM".

See also

cfcollectioncfcomponentcfexecutecfindexIsInstanceOfcfreportcfsearchcfwddxUsing ColdFusion components in the Developing ColdFusion Applications

Attributes

Attribute

Req/Opt

Default

Description

component

Required

 

Name of component to instantiate.

domain

Required

 

The domain to which the user belongs.

name

Required

 

String; name for the instantiated component. The name must not have a period as the first or last character.

password

Required

 

The password to access the COM component.

type

Optional

component

The object type. You can omit this attribute or specify component. ColdFusion automatically sets the type to component .

username

Required

 

The user name to access the COM component.

Pre-requisites

  • If the DLL is hosted on a remote server, register the DLL with the server using JIntegra's "Setdllhost.exe" tool with the host server. To use the tool on the remote server, copy the  jintegra /bin folder to that DCOM server. If you are registering 32-bit DLLs on a 64-bit server, copy the JIntegra tool from a 32-bit installation of ColdFusion.
  • If you are using an express installation of ColdFusion, register the TypeViewer DLL in ColdFusion's lib directory with the DCOM server using JIntegra's  Sethostdll  tool. You may encounter "AutomationException: 0x80040154 - Class not registered." error if the TypeViewer DLL is not registered.

Usage

When the cfobject tag creates an instance of the CFC, ColdFusion executes any constructor code in the CFC; that is, it runs code that is not in the method definitions.On UNIX systems, ColdFusion searches first for a file with a name that matches the specified component name, but is all lowercase. If it does not find the file, it looks for a filename that matches the component name exactly, with the identical character casing.

Example

<!--- Separate instantiation and method invocation; --->
<!--- permits multiple invocations. --->
<cfobject
name="quoteService"
component="nasdaq.quote">
<cfinvoke
component="#quoteService#"
method="getLastTradePrice"
symbol="macr"
returnVariable="res">
<cfoutput>#res#</cfoutput><br>
<cfinvoke
component="#quoteService#"
method="getLastTradePrice"
symbol="mot"
returnVariable="res">
<cfoutput>#res#</cfoutput>
<!--- Separate instantiation and method invocation; ---> <!--- permits multiple invocations. ---> <cfobject name="quoteService" component="nasdaq.quote"> <cfinvoke component="#quoteService#" method="getLastTradePrice" symbol="macr" returnVariable="res"> <cfoutput>#res#</cfoutput><br> <cfinvoke component="#quoteService#" method="getLastTradePrice" symbol="mot" returnVariable="res"> <cfoutput>#res#</cfoutput>
<!--- Separate instantiation and method invocation; ---> 
<!--- permits multiple invocations. ---> 
<cfobject 
name="quoteService" 
component="nasdaq.quote"> 
<cfinvoke 
component="#quoteService#" 
method="getLastTradePrice" 
symbol="macr" 
returnVariable="res"> 
<cfoutput>#res#</cfoutput><br> 

<cfinvoke 
component="#quoteService#" 
method="getLastTradePrice" 
symbol="mot" 
returnVariable="res"> 
<cfoutput>#res#</cfoutput>

Get help faster and easier

New user?