heres what i do when I need to dynamically call functions - make all your
beans inherit this:

<cffunction name="runFunction">
                <cfargument name="functionname" type="string" required="yes">
                <cfargument name="args" type="struct" required="no"
default="#structnew()#">
                <cfset var retval = "">
                <cfinvoke component="#this#"
                                                        
method="#arguments.functionname#"
                                                        
argumentCollection="#arguments.args#"
                                                        returnvariable="retval">
                <cfreturn retval>
        </cffunction>


Then you can:

o.runfunction("set"&colArray[x],q[colArray[x]]);

-----Original Message-----
From: Paul [mailto:[EMAIL PROTECTED]
Sent: 12 October 2005 16:47
To: CF-Talk
Subject: dynamic function call puzzle


My "read" function returns, predictably, a query object with a single row
containing all the columns needed to populate a bean.  It bothers me that to
use the bean I then have to write a code block full of set statements -
mybean.setVariable(queryname.column) - for every property of the bean.



So I'm trying to write a function that takes the result of my "read"
function and automatically sets the bean values.  I've been able to populate
a struct dynamically, but not without using evaluate(), and I can't call my
bean's "set" functions at all.  How can I improve on the following code?



<cfquery name="q" datasource="#getDSN()#">

select *

from TEMPLATES

            where TEMPLATE_ID = <cfqueryparam value="2"
cfsqltype="cf_sql_integer">

</cfquery>



<cfset o=createObject("component","com.redweb.Template").init()>

<cfoutput query="q">

            <cfscript>

                        colArray=listToArray(q.columnlist);



                        //test struct to see if I can get that far.

                        s=structNew();

                        for (x=1; x LTE arrayLen(colArray); x=x+1) {

                                    //this test is ugly but it works

                                    "s.#colArray[x]#"=evaluate(colArray[x]);



                                    //this is not valid but it is
essentially what I want to do...


o.set#colArray[x]#(evaluate(colArray[x]));

                        }

            </cfscript>

</cfoutput>



<cfdump var="#s#">

<cfdump var="#o.getSnapshot()#">





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220813
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to