Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comparing a GUID so I can sort by GUID

what's a nice, fast way to sort a list of GUIDs (as TGuid). i thought i'd just use SysUtils.CompareMem(P1, P2: Pointer; Length: Integer): Boolean; until i realized it returns boolean.

i'd wish for something comparable to CompareText( ) or CompareValue( ) that return integer so it can be used in a sort comparison.

i suppose not many people wish to sort GUIDs...any ideas?

i suppose i could call make some cascading calls to CompareValue( ) on the contents of the TGuid record. my instincts tell me there must be a better way!

thank you!

like image 283
X-Ray Avatar asked Dec 14 '22 01:12

X-Ray


1 Answers

If you're using Delphi 2009 or better, you can use TComparer<TGUID>.Compare(), or the BinaryCompare function it calls, from the Generics.Defaults unit.

like image 122
Barry Kelly Avatar answered Dec 23 '22 09:12

Barry Kelly