Sorry about the var person - I was going to go into further detail about 
creating an array of structs but ripped out everything and forgot to remove 
that...in the code below you don't need it.

But, being that your next question sheds more light on what you're trying to 
do....

I've not done flex in a while but I am almost positive you can bind a flex grid 
to a coldfusion query.  So, it would make more sense for your function to just 
return the query object and then bind that straight to your grid.  I'm assuming 
you're calling this via a CFC from flex, and there should be many examples of 
that out there.  Your array of arrays will probably be 100x more tedious than 
doing the query to grid binding.

Hope that helps.


________________________________
From: ad...@acfug.org [mailto:ad...@acfug.org] On Behalf Of Chris H
Sent: Thursday, September 09, 2010 1:09 PM
To: discussion@acfug.org
Subject: Re: [ACFUG Discuss] newbie question: storing an array variable into a 
variable whose data type is not specified

Thanks Steve, Jay, Clark and Axunderwood for the prompt responses and useful 
suggestions.

1.  I have changed the return type of function to "struct" and other changes in 
the function as below according to the suggestions

<cffunction name="myfunction" access="remote" returntype="struct">
        <cfargument name="form_data" type="struct">

<cfset var result = StructNew() />
<cfset var person = "" />   <!--- Why is this needed? I did not understand this 
part. I realize the concept is to initialize variables with blank values before 
using them --->

<cfset result['dept_name'] = "some dept"
<cfset result['dept_num'] = "some dept number"
.
.......

           <cfscript>
                  ArrayAppend(peoplearray, #printPeople.empID#);
                  ArrayAppend(peoplearray, #printPeople.departmentname#);
                  ArrayAppend(peoplearray, #printPeople.departmentID#);
                  ArrayAppend(peoplearray, #printPeople.empTitle#);
          </cfscript>

.        <cfset result['people_info'] = peoplearray

                <cfset result['statMsg'] = 'Information successfully 
collected.'>
                <cfset result['status'] = true>

     <cfreturn result>

</cffunction>

Rest of part is same as I posted earlier

2. How would I reference the return values in the caller function which is a 
Flex component?

private function myfunction(eventObj:ResultEvent):void{

               var people_obj:Object = new Object();

                people_obj.dept_name = eventObj.result.dept_name;
                people_obj.dept_num = eventObj.result.dept_num;

               // would the below code work?

              people_obj.peoplearray = eventObj.result.peoplearray

    }

// How can I access the department name, department ID and employee ID, title 
of  the third person whose name is John from the above people_obj // object?

// Or, do I need an arraycollection variable

            [Bindable]
            private var people_info:ArrayCollection;
            people_info =  eventObj.result.peoplearray

Then, I could load the arraycollection variable people_info into a DataGrid 
element where the elements would be displayed in order?

Can someone please advise?

Thanks




________________________________
From: Steve Ross <nowhid...@gmail.com>
To: discussion@acfug.org
Sent: Thu, September 9, 2010 9:55:29 AM
Subject: Re: [ACFUG Discuss] newbie question: storing an array variable into a 
variable whose data type is not specified

yep, what you are actually doing is creating a named struct (hash) when you do 
this:

<cfset result['people_info'] = peoplearray />

changing the return type will give you exactly what you want (unless you want 
an array), and if you do then you can create an array of structs...

On Thu, Sep 9, 2010 at 9:51 AM, Chris H 
<h_chris...@yahoo.com<mailto:h_chris...@yahoo.com>> wrote:
Hi All,

I am a newbie to Coldfusion. My development background is mainly in C/C++ so 
please excuse me if my below question is naive.

I have a function as below

<cffunction name="myfunction" access="remote" returntype="any">
        <cfargument name="form_data" type="struct">

<!---  The variable to be returned by the function is "result"  --->

<cfset result['dept_name'] = "some dept"
<cfset result['dept_num'] = "some dept number"

<!---  I run a query where I want to find some information about people having
name "John" and there can be N number of people with the name of John --->


<cfquery dbtype="query" name="printPeople">
    SELECT *
    FROM people
    WHERE peopleName = "John"
</cfquery>

<cfset peoplearray=ArrayNew(1)>

      <cfset myCounter = 0 />
         <cfloop query="printPeople">

           <cfset myCounter = myCounter + 1 />


          <cfscript>
                  ArrayAppend(peoplearray, #printPeople.empID#);
          </cfscript>

          <cfscript>
                  ArrayAppend(peoplearray, #printPeople.departmentname#);
          </cfscript>


          <cfscript>
                  ArrayAppend(peoplearray, #printPeople.departmentID#);
          </cfscript>


          <cfscript>
                  ArrayAppend(peoplearray, #printPeople.empTitle#);
          </cfscript>

          </cfloop>



                <cfset result['people_info'] = peoplearray <!--- Can this be 
done? --->

                <cfset result['statMsg'] = 'Information successfully 
collected.'>
                <cfset result['status'] = true>

     <cfreturn result>

</cffunction>


The part <cfset result['people_info'] = peoplearray
attempts to store an array variable into a variable whose data type is not 
specified.

Can this be done?

If not, what should I do? Should I define the datatype of "result" variable as 
a structure, change the return type
in function signature as a structure from any as a structure variable
can hold string, integer and array variables?

Any suggestions would be appreciated.


-------------------------------------------------------------
To unsubscribe from this list, manage your profile @
http://www.acfug.org?fa=login.edituserform

For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by FusionLink<http://www.fusionlink.com>
-------------------------------------------------------------



--
Steve Ross
web application & interface developer
http://blog.stevensross.com
[mobile] (912) 344-8113
[ AIM / Yahoo! : zeriumsteven ] [googleTalk : nowhiding ]


-------------------------------------------------------------
To unsubscribe from this list, manage your profile @
http://www.acfug.org?fa=login.edituserform

For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by FusionLink<http://www.fusionlink.com>
-------------------------------------------------------------



-------------------------------------------------------------

To unsubscribe from this list, manage your profile @ 

http://www.acfug.org?fa=login.edituserform



For more info, see http://www.acfug.org/mailinglists

Archive @ http://www.mail-archive.com/discussion%40acfug.org/

List hosted by http://www.fusionlink.com

-------------------------------------------------------------


Reply via email to