RE: Using CreateObject with init correctly
Hi Richard, To init() on create you need to make sure that the init() method returns THIS (cfreturn this /) In your example it seems that you are returning VOID. Cheers, Baz -Original Message- From: Richard East [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 18, 2006 8:36 AM To: CF-Talk Subject: Using CreateObject with init correctly 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, ââ¬ÅVariable 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:229859 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
Re: Using CreateObject with init correctly
Hi Richard, To init() on create you need to make sure that the init() method returns THIS (cfreturn this /) In your example it seems that you are returning VOID. Cheers, Baz Brilliant! That works. Thank you, Richard ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:229862 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
Re: Using CreateObject with init correctly
here's an example from some code I worked on using the jakarta apache Project's HSSp java classes: cfset wb = createObject(java,org.apache.poi.hssf.usermodel.HSSFWorkbook).init()/ this is creating an object that creates an excel spreadshhet workbook... Eric On Wed, 18 Jan 2006 09:36:00 -0400 Richard East [EMAIL PROTECTED] wrote: 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, âVariable 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:229891 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=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: Using CreateObject with init correctly
Here's the entire code snippet... cfset wb = createObject(java,org.apache.poi.hssf.usermodel.HSSFWorkbook).init()/ cfset fileOut = createObject(java,java.io.FileOutputStream).init(#workbookpath#)/ cfset wb.write(fileOut)/ cfset fileOut.close()/ On Wed, 18 Jan 2006 09:57:45 -0500 Baz [EMAIL PROTECTED] wrote: Hi Richard, To init() on create you need to make sure that the init() method returns THIS (cfreturn this /) In your example it seems that you are returning VOID. Cheers, Baz -Original Message- From: Richard East [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 18, 2006 8:36 AM To: CF-Talk Subject: Using CreateObject with init correctly 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, ââ¬ÅVariable 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:229892 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
Re: Using CreateObject with init correctly
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
RE: Using CreateObject with init correctly
Initiating a Java object in the same line as creating it does not work all the time. It depends on how the Java object is coded and how its constructors are built. I ran into this when using the Java file read objects. When using these, one must assign the object with the create object function then init the object on a second line. It just does not work on one line. -- Ian Skinner Web Programmer BloodSource www.BloodSource.org Sacramento, CA 1 Binary Soduko C code. C code run. Run code run. Please! - Cynthia Dunning ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:229900 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