>- see footer for list info -<
The OO nazis out there will scream encapsulation at you. Having it in the
THIS scope will mean you can get at and modify the data any way you choose.

Continuing on from your code:

<!--- use createobject to initiate the cfc --->
<CFSET objCFC=CreateObject("component","myCFC")>
<!--- collect a varible that CFReturn would usually return from a cfc --->
<CFSET getReturnedData=objCFC.myFunction("optional arguments go here")>

<!--- Let's bugger up the data!!! --->
<cfset objCFC.myquery = "Not a query any more sucker!">

<!--- get the var/object that was explosed using the This scope --->
<CFSET myquery=objCFC.myquery>

It's a bit of a silly example, but it highlights the point. You (might) want
to aim for controlled access and modification of your CFC data, using THIS
allows another more direct path to getting at this data which bypasses any
checks you can have in place.

I'm not a CFC expert, but I do know OO (I think!).

Ade

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Gary F
Sent: 29 December 2005 13:10
To: [email protected]
Subject: [CF-Dev] The THIS scope in CFCs


>- see footer for list info -<
I posted a similar message on Ray Camden's Ask a Jedi blog but it created
more questions than answers. I need to return at least 2 complex objects
(queries) from a CFC. The CFRETURN function only lets you return a single
object/variable so I started using the THIS scope.

Example: from within the CFC
<CFSET this.myquery=myquery>

Now myquery is exposed to the parent page so I can grab it like so:

<!--- use createobject to initiate the cfc --->
<CFSET objCFC=CreateObject("component","myCFC")>
<!--- collect a varible that CFReturn would usually return from a cfc --->
<CFSET getReturnedData=objCFC.myFunction("optional arguments go here")>
<!--- get the var/object that was explosed using the This scope --->
<CFSET myquery=objCFC.myquery>

I found this is the quickest and most effecient way to return multiple
vars/objects from CFCs without storing them in arrays or structures which
seems like a waste of code when This works with total simplicity. Someone
told me using the This scope is bad practice but failed to give a reason. I
honestly don't see what's wrong with this, but I'd like to hear the thoughts
of experienced CFC users? (I've only been using CFCs for a few months).

Thanks,
Gary.

_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to 
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<

Reply via email to