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]

Reply via email to