Author: Jonas Bilinkevicius
How can I create a TStringlist cousin which holds integers rather than strings. I
need the ability to keep a list of objects sorted by an integer with full binary
IndexOf.
Answer:
Use a TList, and do casts where appropriate:
To write:
1 MyList.Add(Pointer(17));
2 MyList.Add(Pointer(39));
3 4 //To read:5 6 MyInt := Integer(MyList[0]);
7 8 //To sort:9 10 procedure CompareInts(Item1, Item2: Pointer): Integer;
11 begin12 if Integer(Item1) > Integer(Item2) then13 Result := 1
14 elseifif Integer(Item1) < Integer(Item2) then15 Result := -1
16 else17 Result := 0;
18 end;
19 { ... }20 MyList.Sort(CompareInts);