That is the crucial key I needed! Much easier than what I had tried to do with the meta data too -- bonus!
>like a cfinclude file (even with a dynamic file name) from inside the CFC Is this to get around the inability to nest <cffunction> tags in CFC's? That's definitely a hurdle... any speculation as to why CF doesn't offer us a Function object we could create and modify, without having to use CF-tags or cfscript? Or does it? I'd prefer to create a blank function object, then fill it up with the details... Hmm. Just how would I set the functionality of the function without a cffunction tag. I'd almost need... another function :P Well, alright, that's a little trickier than I had first thought. So it seems accepted practice to include a .cfm file from your component to get around that. Anyone care to play devils advocate against that practice? If I'm dynamically writing the .cfm file content (which I will be doing), I then just include that .cfm file within my function and reference my function (stored as a variable) from there. Interesting... Am I still on track, or wildly flailing in the wind? :) Jonathon -----Original Message----- From: Nathan Strutz [mailto:[EMAIL PROTECTED] Sent: Monday, October 22, 2007 1:16 PM To: CF-Talk Subject: Re: programmatically add functions to a CFC Jonathon, You're on the right track, but it's much easier than that. Here's some play code I just whipped up: <cfscript> function getVariablesExternal() {return variables;} function methodToInject() {return "This method was Injected";} myCFC = createObject("component","test").init(); // get component myCFC.getVariables = getVariablesExternal; // inject variable scope getter into "this" scope myCFC.getVariables().injectedMethod = methodToInject; // inject a method into CFC "variables" scope myCFC.getVariables().this.injectedMethod = methodToInject; // also into public "this" scope writeOutput( myCFC.getVariables().privateMethod() ); // call private method from test.cfc writeOutput( myCFC.injectedMethod() ); // call injected method </cfscript> It's really amazing the things you can do with this stuff :D PS here's my test.cfc: <cfcomponent> <cffunction name="init" access="public"> <cfreturn this> </cffunction> <cffunction name="privateMethod" access="private"> <cfreturn "This is a Private Method!"> </cffunction> <cffunction name="publicMethod" access="public"> <cfreturn "This is a Public Method!"> </cffunction> </cfcomponent> This is actually the concept of mix-ins, there has been some more formal code written about it, but you can do it like this, like a cfinclude file (even with a dynamic file name) from inside the CFC, you can get a struct of functions and loop over them, calling each or injecting them elsewhere, you can have a mixin() method that takes a function as an argument, and so on and so on. Really, lots of fun things here! -- nathan strutz http://www.dopefly.com/ On 10/22/07, Jonathon Stierman <[EMAIL PROTECTED]> wrote: > > Is it possible to programmatically add/update functions to an instantiated > CFC? > > I've made one attempt to add one by calling the getMetaData function, but > nothing I added to the meta data seemed to update the object's method > list. > > Is there another way to go about doing this, or am I on the right track? > > Jonathon > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Download the latest ColdFusion 8 utilities including Report Builder, plug-ins for Eclipse and Dreamweaver updates. http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:291789 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4