Description

The CreateObject function can create an instance of a ColdFusion component (CFC) object.

Returns

A component object.

Function syntax

CreateObject(type, component-name, domain, username, password)

History

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

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

See also

Building and Using ColdFusion Components in the Developing ColdFusion Applications

Parameters

Parameter

Description

type

(Optional) - Type of object to create. The default value of type is component.
  • com
  • corba
  • java
  • component
  • webservice

component-name

The CFC name; corresponds to the name of the file that defines the component; for example, use engineComp to specify the component defined in the engineComp.cfc file

domain

The domain to which the user belongs.

username

The user name to access the COM component.

password

The password of the above user name.

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 Col dFusion, 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

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.In the following example, the CFScript statements assign the tellTimeCFC variable to the tellTime component using the CreateObject function. The CreateObject function references the component in another directory. To invoke component methods, you use function syntax.

<b>Server's Local Time:</b> 
<cfscript> 
tellTimeCFC=CreateObject("component","appResources.components. 
tellTime"); 
tellTimeCFC.getLocalTime(); 
</cfscript> 
<br> 
<b>Calculated UTC Time:</b> 
<cfscript> 
tellTimeCFC.getUTCTime(); 
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy