the singularity of being and nothingness
Gotcha with Dynamic Component Method Invocation
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]; dyn();
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.
Print article | This entry was posted by existdissolve on September 30, 2010 at 2:59 am, and is filed under ColdFusion. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |