The problem is inside your init() method. You're not returning the object in 
the cfreturn.

<CFFUNCTION name="Init" access="public" returntype="CachedQuery" 
output="false">
  <CFARGUMENT name="DSN" type="String" required="yes">
  <!--- Set the DSN to the local variables for the CFC --->
  <CFSET Variables.DSN=Arguments.DSN>
  <!--- Return the query object --->
  <CFRETURN This>
</CFFUNCTION>
This is the init method of my cachedquery CFC. Note that I'm setting a 
returntype equal to the name of the CFC, but the entire returntype is not 
needed. The main point is that I'm returning THIS which means I'm returning 
the object back to the call to be stored in the external variable.

Using this call:
<CFSET Application.CachedQuery=CreateObject('Component', 
'Components.CachedQuery').Init(DSN)>
will call the cachedquery CFC, call the init method, pass it the DSN and 
when the method is done, it'll pass the entire CFC back as the value to be 
assigned to the Application.CachedQuery variable.


>I have seen code where an object was created like this:
> <cfset userInfo=CreateObject("component", 
> "objects.player").init(REQUEST.id) />
>
> The method I had been using that works is like this:
> <cfset REQUEST.id = 1 />
> <cfset userInfo=CreateObject("component", "objects.player") />
> <cfset userInfo.init(datasource) />
> <cfset REQUEST.qryUserDetails = userInfo.getUserDetails(REQUEST.id) />
> <cfdump var="#REQUEST.qryUserDetails#"><cfabort />
>
> I have tried the method of initiating the Object as it is created, but 
> when I do I get an error:
>
> <cfset userInfo=CreateObject("component", 
> "objects.player").init(REQUEST.id) />
> <cfset REQUEST.qryUserDetails = userInfo.getUserDetails(REQUEST.id) />
> <cfdump var="#REQUEST.qryUserDetails#"><cfabort />
>
> This fails with the error message, â?oVariable userInfo is undefined.â? 
> Would someone clarify how I can do this correctly and what would be best 
> practice?
>
> Thank you for your help and opinions,
>
> Richard
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:229898
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to