The "typical" way of doing this is via a comparison function and a generic sort routine. So you provide a function that compares two objects and returns their order. The order is often returned as in integer with -1 meaning the first is lesser, 0 meaning they are equal, and +1 meaning the second is lesser.
Then you have some generic sort routine that accepts a collection of objects and your comparison function. That routine does it's sort using your function for all comparison operations. I'm not sure where such a generic sort routine exists (at least in CF), but that's the general idea. cheers, barneyb 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! > -- Barney Boisvert [EMAIL PROTECTED] http://www.barneyb.com/ Got Gmail? I have 100 invites. 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