House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Dynamic cfc function call

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Chris Terrebonne
08/23/2005 02:12 PM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
08/23/2005 02:20 PM

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.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Chris Terrebonne
08/23/2005 02:31 PM

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.


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference