using sortwith question.

I have an array objects.
Each object has a time property in it as a Time object.
I want to sort the array by the time property.
In a loop I built an array of the timestamp of each object and will pass that to sortwith, but I’m not sure sortwith will know how to sort according to a Time object.

Maybe… I should have done an insertion in the array to make sure the array was sorted to begin with, but that sounds like it make take time searching the array for the point of insertion.

I can’t use a dictionary because the time stamps aren’t unique…

Use the SQLDateTime string representation of the Date (Time?) object in the array that you pass to SortWith, and it will sort just fine.

no, sortwith is to sort two array synchronously.

you can use thomas “sortbyproperty” described here
https://forum.xojo.com/26055-tip-smart-sort-function-for-arrays-of-objects/0
or here : http://documentation.xojo.com/index.php/Introspection#Examples

or you can make a compare method

Function MyCompare(value1 as myobject, value2 as myobject) as Integer if greater then return 1 if less then return -1 if equal then return 0 End Function

then do the sort using

myarray.sort ( addressof mycompare)

I thought the OP was building the array of timestamps specifically for the purpose of sorting the array of objects by use of SortWith. Assuming this is the case, TotalSeconds could also be used instead of my original suggestion of SQLDateTime; it would probably be faster.

If not, Jean-Yves’s suggestion is the way to go.

Thanks.