Yeah, we're on CF8 for better or worse.  So I redid the previous function to 
look like this:

<CFFUNCTION name="getPrograms_a" access="public" returntype="Array">

        <CFSET VAR local = {}> 
        
        <CFINVOKE method="getPrograms_q" returnvariable="q_programs">
         
        <CFSET local.a_programs = ArrayNew(1)>        
        <CFLOOP query="q_programs">
                <CFSET local.o_program = createObject('component', 
'#REQUEST.cfcPathDot#.Program').init(programID = q_programs.ProgramID)>         
       
            <CFSET ArrayAppend(local.a_programs, local.o_program)>
        </CFLOOP>
        
        <CFRETURN local.a_programs> 

</CFFUNCTION>


And I'm getting the correct info back now.  Last two questions.  1) should I 
not worry about running 'createObject' on the same local.o_program structure 
member everytime?  It's not completely obvious to me how 'local' magic is 
working.  And is there not a memory leak issue with running createObject on 
every iteration?  2)  Should my previous version have worked?  I don't mind 
doing this 'local' trick everywhere, but I am curious about why the original 
wasn't working properly.

Thanks!

> > If you're on CF9 things may a little different in that you may not 
> need to explicitly var
> > scope,
> 
> If you are on CF9, use the local scope as it is inherently "varred":
> 
> 
> <cfset local.returnArray = []>
...
> 
> <cfset local.thisContact = createObject('component',
> 'Contact').init(...insert init info here...)>
> <cfset ArrayAppend(local.returnArray, local.thisContact)>
> 
> 
> If you are not on CF9, I could recommend still getting in the habit 
> of
> pretending there is a local scope and putting <cfset var local = {}> 
> at
> the top of your method.  Just make sure you reference all of your
> "local" variables as local.varName and this will ensure that multiple
> people hitting that code at the exact same time will all have their 
> own
> special versions of each of those variables and no one will be
> overwriting another.
> 
> ~Brad


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:329656
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