4 Replies Latest reply on Dec 1, 2006 1:13 PM by Newsgroup_User

    Two questions

    sean69 Level 1
      How can I call a function name dynamically?
      i.e. I have a bunch of validation functions that I need to call dynamically. - any thoughts?

      AND... is there a method of telling coldfusion to include all files in a particular directory (without the song and dance of listing the directory, looping through the list etc.. )

        • 1. Re: Two questions
          Dan Bracuk Level 5
          answer 1 - use evaluate

          answer 2 - proably not, but you could always try to use a wildcard. Or, you could write a master include that contains all the other cfincludes. This would allow you to specify the order in which the files run.
          • 2. Re: Two questions
            sean69 Level 1
            Hi Dan;

            Would you please "elaborate" on the "evaluate" <grin>

            I've looked at that function several times, but for some reason or another it's correct use seems to evade me.

            Q2... yea wild cards don't work Ho-well

            • 3. Re: Two questions
              Level 7
              > answer 1 - use evaluate

              As a last resort, maybe.

              // some basic functions
              function f(){
              return true;

              function g(){
              return false;

              // now use a static name, fnToCall, to dynamically call different functions
              fnToCall = f; // "f" being the function we defined above
              writeOutput(fnToCall()); // outputs "true";

              fToCall = g;
              writeOutput(fnToCall()); // now outputs "false";

              Functions can be assigned to variables just like any other value / variable
              / object.

              > answer 2 - proably not,

              Just "no, you can't". You need the song and dance. But if it's the sort
              of thing you're doing on a regular basis (can't think why you would be, to
              be honest), then you should write a UDF that does it, and the you only have
              to sing and dance once. Thereafter: use the UDF.

              • 4. Re: Two questions
                sean69 Level 1
                got it..


                wish I understood it completely though.... thanks for the pointing of the right direction.