That seems like an inordinate amount of code for just setting and returning
properties. I decided to play with the THIS scope, and came up with this:
<cfcomponent>
<cffunction name="init">
<cfset THIS.hasError = false>
</cffunction>
<cffunction name="mymethod">
<cftry>
<!--- some bad code --->
<cfcatch>
<cfset THIS.hasError = true>
</cfcatch>
<cftry>
</cffunction>
</cfcomponent>
Then in the calling page, I have this:
<cfobject component="cfc/mycfc" name="mycfc">
<cfinvoke component="#mycfc#" method="init">
<cfinvoke component="#mycfc#" method="mymethod">
<cfoutput>#mycfc.hasError#</cfoutput>
Am I doing anything illegal or bad there? I had heard that the THIS scope
was available outside the CFC, but I assumed that meant via the THIS scope,
which I found to be not true. Just trying to figure out if I might run into
a problem I'm not seeing by doing things this way.
Thanks,
Dan
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Nando
> Sent: Tuesday, November 09, 2004 10:09 PM
> To: [EMAIL PROTECTED]
> Subject: RE: [CFCDev] How to define a property on a CFC
>
> Ummm, what about a public getter? Or am i missing something?
>
> <cffunction name="getMyProperty" access="public" returntype="string"
> output="false">
> <cfreturn variables.getMyProperty />
> </cffunction>
> <cffunction name="setMyProperty" access="public" returntype="VOID"
> output="false">
> <cfargument name="myProperty" type="string" required="true" />
> <cfset variables.myProperty = arguments.myProperty />
> </cffunction>
>
> <cfset myProperty = myObj.getMyProperty() />
>
> store the object in session or application scope if the
> properties should
> persist, but if you do, make sure to var scope any variables
> used in the
> functions that you use to manipulate values.
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Daniel Short
> Sent: Wednesday, November 10, 2004 6:52 AM
> To: [EMAIL PROTECTED]
> Subject: [CFCDev] How to define a property on a CFC
>
>
> Hi everyone,
>
> I'm trying to figure out how to set a property on a CFC and
> reference it on
> my calling page. In VBScript I can define as many properties
> as I'd like and
> reference them via objName.PropertyName. I'm assuming that's
> possible with
> local CFCs (I'm not intersted in web services at all on this
> one), but the
> livedocs suggest that cfproperty is webservice specific. I'm
> not finding any
> other method to make this happen beyond using the THIS scope. My vague
> knowledge of the THIS scope is that this scope is available (and
> overwritable, manipulatable) in the calling page, which isn't what I'm
> after. I need a read-only property that can only be
> manipulated from inside
> the CFC.
>
> I have a feeling that I'm missing something really simple
> here, but I just
> can't get it.
>
> Dan
>
>
> ----------------------------------------------------------
> 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
> [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
> [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
[EMAIL PROTECTED]