FYI - You can save a few implicit type conversions by removing your single quotes and pound signs - as in:
<cfset variables.instance[column] = contact[column][1]> Roland -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ken Dunnington Sent: Friday, April 30, 2004 2:56 PM To: [EMAIL PROTECTED] Subject: Re: [CFCDev] CFC method returning complex value? In case anyone is interested, I figured this problem out. This line: <cfset variables.instance['#column#'] = contact['#column#']> was the problem. When you access a query object with index notation, and don't specify a row number, the result is a 1 dimensional array, even if there is only one row returned (as in this case.) The solution was to change the line to the following: <cfset variables.instance['#column#'] = contact['#column#'][1]> Ken On Apr 30, 2004, at 2:24 PM, Ken Dunnington wrote: > I am writing some CFC's, one of which is a Contact Manager. In order > to allow for a large number of fields (and to save myself some typing) > I am populating the CFC's properties on initialization by looping over > the query columns, and assigning variables dynamically. This seems to > work fine; when I dump the instance data, I can see my fields > populated with the proper values. I have also written a multi-purpose > 'get' method which will fetch any variable from the instance data. > When I try to use this method, however, to retrieve a field, say > "first", I get a 'Complex object types cannot be converted to simple > values' error. However, if I first save the result of the get method > into a local variable, I can use it as expected (as a string.) > > In earlier objects, I've used this get method without problems, the > difference being I explicitly defined the variables in the instance > data. Why would I get this error only when accessing the method > directly? > > Here is the code for the get method: > > <cffunction name="get" output="no" hint="Get a variable from the > instance data"> > <cfargument name="what" type="string" required="yes" hint="Item to > get"> > <cfif StructKeyExists(variables.instance,arguments.what)> > <cfreturn variables.instance["#arguments.what#"]> > <cfelse> > <cfreturn ''> > </cfif> > </cffunction> > > And here is the code I use to populate the variables.instance struct: > > <cfquery name="contact" datasource="#variables.ds#"> > SELECT * FROM contact > WHERE id = "#arguments.id#" > </cfquery> > > <cfif contact.RecordCount GT 0> > <cfloop list="#contact.columnList#" index="column"> > <cfset variables.instance['#column#'] = contact['#column#']> > </cfloop> > </cfif> > > Note that the get method has no return type, because it is used to get > both simple and complex values, but the value I am trying to get is a > string. > > Thanks, > Ken > > ---------------------------------------------------------- > You are subscribed to cfcdev. To unsubscribe, send an email > to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the > message of the email. > > CFCDev is run by CFCZone (www.cfczone.org) and supported > by Mindtool, Corporation (www.mindtool.com). > > An archive of the CFCDev list is available at > www.mail-archive.com/[EMAIL PROTECTED] > ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com). An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED] ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com). An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
