Article Preview
Buy Now
COLUMN
Sorting Variants
Create Your Own Custom Sorting Methods
Issue: 23.2 (March/April 2025)
Author: Marc Zeedar
Author Bio: Marc taught himself programming in high school when he bought his first computer but had no money for software. He's had fun learning ever since.
Article Description: No description available.
Article Length (in bytes): 11,774
Starting Page Number: 59
Article Number: 23206
Resource File(s):
project 23206.zip Updated: 2025-03-02 13:15:06
Related Link(s): None
Excerpt of article text...
If you're like me, you love that Xojo has a built-in method for sorting arrays:
myArray.sort
. Unfortunately, this only works with strings and numbers. If the array contains objects likefolderItems
,dateTime
items, or your own custom class, it can't be sorted.I've run into this so often that I have created utility routines that sort these by temporarily copying the items into a new array with the data in string format and sorting that. For example, for dates, I might convert them to
SQLDate
. Then I have to convert them back and replace the original array with the new one.Since Xojo is so fast and my data needs aren't huge, this isn't a slow process—but it is inefficient and has always bugged me. Looking through Xojo's example projects, I noticed a sort example that takes a different approach. Here, we create our own compare method that gets passed to the sort routine, like this:
myArray.sort(addressOf dateCompare)
...End of Excerpt. Please purchase the magazine to read the full article.