In an app I’m currently working on, I came across the need to be able to invoke methods from a particular component dynamically. On the surface, this is pretty simple:

myComp = createobject("component","com.utils").init();
dyn = myComp[methodvariable];

While this technically *works*, there is one huge gotcha: there does not appear to be any persistence of the initialized component from init() to dyn(). That is, if the init method, say, sets up datasource names and other component properties, these will no longer be available in the invocation of dyn(). Not a big deal, I guess, if you don’t have need of the init function…but a killer if you do.

Fortunately, it’s easy enough to work around this. After you’ve instantiated the component, just use to call the dynamic method:

<cfinvoke component="#myComp#" method="#methodvariable#" />
(cfinvoke is still tag-bound...sorry! :))

Anyway, easy enough, but something a person can easily spend FAR too much time trying to work out. Uggh.