On 2/5/2014 5:24 PM, waldo kitty wrote:
i'm unsure what to do or how to handle this so that there is a secondary
(sub) sorting order so that the main key is the master sort and then a
secondary ""key"" is used when duplicates are allowed...

You put both key comparisons in the same .Compare function.

In one of my Turbo Pascal projects, I used this:

PSystems=^TSystems;
TSystems=object(TSortedCollection)
  function Compare(Key1, Key2: Pointer): Integer; virtual;
  function GetSize:longint;
end;

...

Function TSystems.Compare;

begin
  if PSystem(Key1)^.score < PSystem(Key2)^.score
    then Compare := -1
    else if PSystem(Key1)^.score > PSystem(Key2)^.score
      then Compare := 1
      {Score is the same.  Second search key (larger numbers are worse:}
      else if usectotal(Key1) > usectotal(Key2)
        then Compare := -1
        else if usectotal(Key1) < usectotal(Key2)
          then Compare := 1
          {usec totals same.  Third search key:}
          else if PSystem(Key1)^.BIOSCRC16 < PSystem(Key2)^.BIOSCRC16
            then Compare := -1
            else if PSystem(Key1)^.BIOSCRC16 > PSystem(Key2)^.BIOSCRC16
              then Compare := 1
              else Compare := 0;
end;

--
Jim Leonard (trix...@oldskool.org)
Check out some trippy MindCandy: http://www.mindcandydvd.com/
A child borne of the home computer wars: http://trixter.oldskool.org/
You're all insane and trying to steal my magic bag!
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to