CreateObject() - How to create a ColdFusion object (type component)

CreateObject() - create a coldfusion object (type component)

CreateObject.cfm



<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CreateObject function example: how to create a coldfusion object (type component)</title>
</head>

<body>
<h2 style="color:Crimson">CreateObject Function Example: Component</h2>

<cfset MyObject=CreateObject("component","MyComponent")>

<cfoutput>
 <b>MyObject.Sum(10,25):</b> #MyObject.Sum(10,25)#
    <br /><br />
</cfoutput>
<cfdump var="#GetMetaData(MyObject)#" label="MyObject" >
</body>
</html>


MyComponent.cfc


<cfcomponent output="no" Author="Jones" displayname="Math">
 <cffunction name="Sum" access="remote" returntype="numeric" description="Sum two numbers">
  <cfargument name="Value1" type="numeric" required="yes">
  <cfargument name="Value2" type="numeric" required="yes">
  <cfset Sum=arguments.value1+arguments.value2>
  <cfreturn Sum>
 </cffunction>
</cfcomponent>







More ColdFusion examples