Hi Jonathon,

There's only one thisContact variable, which is being reused each time
through the loop.  So all you need to do is put:

<cfset var thisContact = "">

right at the start.  There's an indeterminate number of values that are
passing through that one variable on their way into the array, but it's
still one variable.

And of course var scope returnArray and q_Contacts as well.  If you're on
CF9 things may a little different in that you may not need to explicitly var
scope, but I'll let the CF9 gurus pick that one up.


Jaime
On Thu, Jan 14, 2010 at 4:26 PM, Jonathan Price <
jonat...@imakehthissound.com> wrote:

>
> So, I'm relatively new to OO in ColdFusion, and I'm banging my head against
> one issue in particular.  Let's say I've got a DAO or Gateway object in my
> APPLICATION scope that needs to return a collection of beans, I'm having
> trouble understanding the need to VAR scope all internally used variables
> when I've got a dynamic number of objects being returned.  That's not very
> clear, so let's say this is the function in question:
>
> <cffunction name="getContacts" access="public" returntype="Contact[]">
>
>   <cfset returnArray = ArrayNew()>
>   <cfset q_Contacts = "">
>
>   <cfquery name="q_Contacts">
>   SELECT *
>   FROM Contacts
>   </cfquery>
>
>  <cfloop query="q_Contacts">
>       <cfset thisContact = createObject('component',
> 'Contact').init(...insert init info here...)>
>       <cfset ArrayAppend(returnArray, thisContact)>
>  </cfloop>
>
>  <cfreturn returnArray>
> </cffunction>
>
> So, my concern is with the inability to create the Contact objects in the
> VAR scope since I don't know how many I'll be creating before hand.  If I do
> it like this (i.e. without the VAR on the createObject), am I setting myself
> up problems?  If so, how should I handle this?
>
> Thanks again, and I hope it's not to ridiculous a question.
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329653
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to