Thanks Sean and Nathan. Crystal clear

Vinny 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Sean A Corfield
Sent: zaterdag 17 januari 2004 20:31
To: [EMAIL PROTECTED]
Subject: Re: [CFCDev] <cfobject> and <cfinvoke> VS createObject

On Jan 17, 2004, at 3:04 AM, Kairoh! wrote:
> I started using Coldfusion when Coldfusion MX was released. I always 
> try to use the latest tags, features in favor of older tags or 
> features.
> Based on
> this practice I am using <cfobject> and <cfinvoke> wherever I can 
> instead of CreateObject(). However, in lots of code examples I see on 
> this list
> CreateObject() is used in favor of <cfobject> and <cfinvoke>. Is there 
> a special reason for this?

There's no difference between this:

<cfset obj = createObject("component","path.to.myCFC") /> <cfset result =
obj.someMethod(42) />

and:

<cfobject action="create" component="path.to.myCFC" name="obj" /> <cfinvoke
component="#obj#" method="someMethod" theArgument="42" 
returnvariable="result" />

other than stylistic preference. I prefer the former as I think it is
clearer (and it is less typing). Oh, and for <cfinvoke> you have to know the
argument names for the method whereas you do not need to know them for the
script-style call - you only have to know their order.

Note the use of #obj# as the component argument in the <cfinvoke> too, to
reuse the instance that is already created. If you do this:

<cfinvoke component="path.to.myCFC" method="someMethod" 
theArgument="42" returnvariable="result" />

then you are creating a new instance of the CFC (and throwing it away after
calling 'someMethod'). It is the equivalent of:

<cfset aTemporaryVariable = createObject("component","path.to.myCFC") />
<cfset result = aTemporaryVariable.someMethod(42) />

(and then never using aTemporaryVariable again).

Sean A Corfield -- http://www.corfield.org/blog/

Got Mach II? -- http://www.mach-ii.com/

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool,
Corporation (www.mindtool.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to