In some sense - cfproperty does nothing but add metadata to to the CFC.
It does NOT auto validate. For example:
<cfproperty name="foo" type="array">
<cfset this.foo = structNew()>
will not throw an error.
In general - all cfproperty does is add metadata to a CFC. However, this
can be very powerful. I've written a UDF, for example, that allows me to
specify <cfproperty> tags in a CFC and then call a validation routine.
For example:
(in the cfc)
<cfproperty name="alpha" type="numeric" required="false">
<cfproperty name="beta" type="numeric" required="true">
<cfproperty name="gamma" type="numeric" required="false" range="1,5">
(in the caller)
<cfset ob = createObject("component","test")>
<cfset ob.init(1,2,99)>
THe init function could set this.alpha, beta, and gamma to the values.
The method would then call the validation routine. Because cfproperty
info is stored in the metadata, I can check to make sure alpha is
numeric (but don't care if it's not passed), beta is numeric, and gamma
is numeric and in the range of 1 to 5. Nothing in CFCs will directly do
this. I have to write my own validation - but the nice thing is that
once I write the validation routine once, I can use it again in other
CFCs. (I plan on making this routine available sometime soon.)
=======================================================================
Raymond Camden, ColdFusion Jedi Master for Macromedia
Email : [EMAIL PROTECTED]
Yahoo IM : cfjedimaster
"My ally is the Force, and a powerful ally it is." - Yoda
> -----Original Message-----
> From: jon hall [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 08, 2002 9:36 PM
> To: CF-Talk
> Subject: Re: CFC's question and the Arguments. (cfproperty vs this)
>
>
> Sorry old thread, but got a question that would fit perfectly.
>
> What is the real difference between using cfproperty and the this
> scope? Are the only advantages the datatype validation?
>
> --
> jon
> mailto:[EMAIL PROTECTED]
>
> Wednesday, August 7, 2002, 9:55:02 PM, you wrote:
> HH> Sean,
>
> HH> Was making the "this" scope public intentional or just something
> HH> inadvertent that slipped through?
>
> HH> -----Original Message-----
> HH> From: Sean A Corfield [mailto:[EMAIL PROTECTED]]
> HH> Sent: Wednesday, August 07, 2002 8:09 PM
> HH> To: CF-Talk
> HH> Subject: Re: CFC's question and the Arguments.
>
>
> HH> On Tuesday, August 6, 2002, at 11:13 , Hal Helms wrote:
> >> You can refer to a passed value either as
> arguments.varName or just
> >> varName. I personally prefer the arguments.varName.
>
> HH> I agree with Hal - be explicit.
>
> >> The "this" scope provides the global scope I think you're
> looking for.
>
> HH> "this" creates *public* data members that are accessible
> directly from
> HH> *outside* the component...
>
> >> <cfcomponent hint="I am a Person">
> >> <cfset this.firstName = "">
> >> <cfset this.lastName = "">
> >>
> >> <cffunction name="setFirstName">
> >> <cfargument name="firstName" type="string" required="yes">
> >> <cfset this.firstName = arguments.firstName>
> >> </cffunction>
> >> </cfcomponent>
>
> HH> I can now do:
>
> HH> <cfset x = createObject("component","person")/>
> HH> <cfset x.firstName = "Mickey"/>
>
> HH> i.e., without calling setFirstName().
>
> HH> If you want a *private* data member (and you normally
> should!), then use
>
> HH> the unnamed scope:
>
> HH> <cfcomponent hint="I am a Person">
> HH> <cfset firstName = "">
> HH> <cfset lastName = "">
>
> HH> <cffunction name="setFirstName">
> HH> <cfargument name="firstName" type="string" required="yes">
> HH> <cfset firstName = arguments.firstName>
> HH> </cffunction>
> HH> </cfcomponent>
>
>
______________________________________________________________________
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists