To answer the basic question, yes, you'd have to write something to sort
based on the criteria you need. The same would apply to an array of
structures or any other similar complex value.

At a more fundamental level, I'd be curious to know why you feel that you
need an array of objects rather than a simple query. Is there a specific
reason a query won't work for your purposes?

One option seems to be to do the sorting within your SQL and simply populate
the array of objects based on the results of the query. Another option is
something like Peter Bell's Iterating Business Object approach. Trying to
mimic the sorting capabilities of SQL seems like it would be a very
open-ended and fairly complex endeavor (especially to build something
reusable and generic).


On 8/20/07, Justin Treher <[EMAIL PROTECTED]> wrote:
>
> I'm doing the OOP thing with the help of many tutorials from all over.
>
> I've run into a stump. I'm returning arrays of objects and using those
> arrays to populate tables and forms. My object is composed of another
> subject (member class has a membershipType class).
>
> I'm trying to figure out how to sort my array of objects by any of the
> instance properties (using the getters). Since I'm using a composed
> object,
> sorting directly from the database is out of the question.
>
> I'm guessing it will go something like this:
> unsortedArray = application.memberService.getMembers()
> sortedArray = arrayNew(1)
>
> //loop through unsorted array
> Loop from=1 to=arrayLen(unsortedArray) index=x
>   //nested loop through sorted array
>   Loop from=1 to=arrayLen(sortedArray) length index xx
>   //compare strings, if true i.e. string 1 (sorted) is greater (further up
> the alphabet), insert at current
>   If
>
> (stringcompare(sortedarray[xx].getFirstName(),unsortedArray[x].getFirstName(
> ))
>     arrayInsertAt(sortedArray,xx,unsortedArray[x])
>
>
> That's the basic of what I'm trying to accomplish, but I'm sure there must
> be a CFC out there for this type of sorting. I'd also like to have
> multiple
> column sorts like the order bys from the database.
>
> Thanks!
>
>
>
>
>
>
>
>
>
>
> You are subscribed to cfcdev. To unsubscribe, please follow the
> instructions at http://www.cfczone.org/listserv.cfm
>
> CFCDev is supported by:
> Katapult Media, Inc.
> We are cool code geeks looking for fun projects to rock!
> www.katapultmedia.com
>
> An archive of the CFCDev list is available at
> www.mail-archive.com/cfcdev@cfczone.org
>
>


You are subscribed to cfcdev. To unsubscribe, please follow the instructions at 
http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org

Reply via email to