|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Dynamic cfc function call
I am attempting to dynamically call a cfc's functions without resorting to evaluate, but something isn't working correctly.Chris Terrebonne 08/23/05 02:12 P Yes, you're exactly right. When you pull a method out of a CFC, it'sBarney Boisvert 08/23/05 02:20 P That sounds like it would work.Chris Terrebonne 08/23/05 02:31 P I am attempting to dynamically call a cfc's functions without resorting to evaluate, but something isn't working correctly. I have read in the archive that you can assign a function to a var, then call the var as a method but this doesn't appear to be working with setters in a cfc. Take the following code for example: tempSetter = myComponent["setID"]; tempSetter(1); Although the function appears to complete without error, the value isn't retained in the myComponent cfc. It almost appears as if the dynamic function is executing in an entirely different scope. If I create another dynamic function call to retrieve the data, it appears to be there, but if I call the function directly, the data isn't there: tempGetter = myComponent["getID"]; writeoutput(tempGetter()); // displays "1" writeoutput(myComponent.getID()); //displays nothing Is there something I'm missing? TIA, Chris This email and its attachments may contain confidential information which is intended only for the use of the person(s) named above. If you are not the intended recipient, you are hereby advised that any disclosure, copying, distribution or the taking of any action based on the contents of this information is prohibited. If you have received this transmission in error, please notify the sender and delete this email from your computer. Thank you. Yes, you're exactly right. When you pull a method out of a CFC, it's no longer part of the CFC. In your setter, you're setting variables.XXX, which outside a CFC, is part of the page's variables scope. When you call the extracted getter, it uses the page's variable scope as well, so it works as well. Since the CFC doesn't use the page's variable scope, the in-CFC methods aren't refering to the same variable, and consequently don't work as expected. If you want to call a method dynamically, take a look at CFINVOKE. You still invoke the method on the CFC instance, but you can pass in a dynamically computed method name. Would that meet your need? cheers, barneyb ----- Excess quoted text cut - see Original Post for more ----- -- Barney Boisvert bboisvert@gmail.com 360.319.6145 http://www.barneyb.com/ Got Gmail? I have 50 invites. That sounds like it would work. Thanks! Chris >>> bboisvert@gmail.com 08/23/05 01:18PM >>> Yes, you're exactly right. When you pull a method out of a CFC, it's no longer part of the CFC. In your setter, you're setting variables.XXX, which outside a CFC, is part of the page's variables scope. When you call the extracted getter, it uses the page's variable scope as well, so it works as well. Since the CFC doesn't use the page's variable scope, the in-CFC methods aren't refering to the same variable, and consequently don't work as expected. If you want to call a method dynamically, take a look at CFINVOKE. You still invoke the method on the CFC instance, but you can pass in a dynamically computed method name. Would that meet your need? cheers, barneyb ----- Excess quoted text cut - see Original Post for more ----- -- Barney Boisvert bboisvert@gmail.com 360.319.6145 http://www.barneyb.com/ Got Gmail? I have 50 invites.
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||