Title: Message
I'd go with his second. If you need it in cfscript, here's an (untested) UDF for you:
   
<cffunction name="invoke">
    <cfargument name="component" required="Yes" type="string" />
    <cfargument name="method" required="Yes" type="string" />
    <cfargument name="args" required="No" type="struct" />
    <cfif ArrayLen(arguments) GT 2>
        <cfinvoke component="#arguments.component#" 
            method="#arguments.method#" 
            returnvariable="tmpReturn"/>
    <cfelse>
        <cfinvoke component="#arguments.component#"
            method="#arguments.method#"
            argumentcollection="#arguments.args#" 
            returnvariable="tmpReturn"/>
    </cfif>
    <cfreturn tmpReturn />
</cffunction>
then call it like this:
 
var obj = "dataObj";
var methd = "getStateData()";
var newVar = invoke(obj,methd);
structInsert(*yourscope*, newVar);
 
 
any flaws in that? please tell me so I know.

--
Eric C. Davis
Programmer/Analyst I
Georgia Department of Transportation
Office of I.T. Applications
Web Applications Group
404.463.2860.158
[EMAIL PROTECTED]

-----Original Message-----
From: Joe Eugene [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 17, 2003 3:59 PM
To: [EMAIL PROTECTED]
Subject: Re: [CFCDev] Dynamic CFC Calls

Thanks Samuel... but that does NOT work.
 
The only way i can get it to work is using an evaluate.... and i really dont want to use "evaluate"
 
 variables.execMethod="request."&variables.varClass&"."&variables.varMethod;
 '#variables.varName#'= evaluate(variables.execMethod);
 
Your Code...
 variables[varName] = request[variables.varClass][variables.varMethod](); // Complains about "()"
 
The compiler complains about the "()" at the end... can u get it to work?
 
Thanks
Joe Eugene
 
 
 
----- Original Message -----
Sent: Tuesday, June 17, 2003 3:45 PM
Subject: RE: [CFCDev] Dynamic CFC Calls

two ways, 
 
1.
 
request.dataObj = createObject("Component","Website/MyData");
 
varObj="dataObj";
varMethod="getStateData"; // removed the parens
varName="someData";
 
variables[varName] = request[varObj][varMethod]();
 
2.
 
<cfinvoke component="#request[varobj]#" method="#varMethod#" returnVariable="#varName#">
 
 
Untested but both should work.
 
hth,

Sam
 
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Joe Eugene
Sent: Tuesday, June 17, 2003 3:38 PM
To: [EMAIL PROTECTED]
Subject: [CFCDev] Dynamic CFC Calls

Anybody know how to dynamically call methods in CFC's
 
<cfscript>
request.dataObj = createObject("Component","Website/MyData");
 
varObj="dataObj";
varMethod="getStateData()";
varName="someData";
 
 
// Now, i want to be able to call the CFC Dynamically, something like
 
'#varName#'=request["#varObj#"]["#varMethod#"];
 
//.#varMethod# doesnt work either.
 
</cfscript>
 
I am getting the below from the above code.
"Element getleftNavLinks is undefined in a Java object of type class coldfusion.runtime.TemplateProxy referenced as"
 
What am i missing?..
 
Thanks
Joe Eugene

Reply via email to