| 1 |
unit Sort; |
| 2 |
|
| 3 |
interface |
| 4 |
uses |
| 5 |
Windows, Messages, SysUtils, Classes, Controls, Forms, |
| 6 |
BoardGroup,DateUtils; |
| 7 |
|
| 8 |
function CategorySortProc(Item1, Item2: Pointer): integer; |
| 9 |
function BoardSortProc(List: TStringList; Item1, Item2: Integer): integer; |
| 10 |
function ThreadItemSortProc(List: TStringList; Item1, Item2: Integer): integer; |
| 11 |
function CompareBool(Item1, Item2: Boolean): integer; |
| 12 |
function CompareInt(Item1, Item2: Integer): Integer; |
| 13 |
function CompareDate(Item1, Item2: TDateTime): Integer; |
| 14 |
|
| 15 |
var |
| 16 |
SortOrder: Boolean; |
| 17 |
SortIndex: Integer; |
| 18 |
SortNoFlag: Boolean; |
| 19 |
SortNonAcquiredCountFlag: Boolean; |
| 20 |
|
| 21 |
implementation |
| 22 |
|
| 23 |
function CategorySortProc(Item1, Item2: Pointer): integer; |
| 24 |
var |
| 25 |
CategoryItem1: TCategory; |
| 26 |
CategoryItem2: TCategory; |
| 27 |
begin |
| 28 |
CategoryItem1 := TCategory(Item1); |
| 29 |
CategoryItem2 := TCategory(Item2); |
| 30 |
|
| 31 |
if SortNoFlag then |
| 32 |
Result := CompareInt(CategoryItem1.No, CategoryItem2.No) |
| 33 |
else |
| 34 |
Result := AnsiCompareText(CategoryItem1.Title, CategoryItem2.Title); |
| 35 |
|
| 36 |
if not SortOrder then |
| 37 |
Result := Result * -1; |
| 38 |
end; |
| 39 |
|
| 40 |
function BoardSortProc(List: TStringList; Item1, Item2: Integer): integer; |
| 41 |
var |
| 42 |
BoardItem1: TBoard; |
| 43 |
BoardItem2: TBoard; |
| 44 |
begin |
| 45 |
BoardItem1 := TBoard(List.Objects[Item1]); |
| 46 |
BoardItem2 := TBoard(List.Objects[Item2]); |
| 47 |
if SortIndex = 0 then |
| 48 |
if SortNoFlag then |
| 49 |
Result := CompareInt(BoardItem1.No, BoardItem2.No) |
| 50 |
else |
| 51 |
Result := AnsiCompareText(BoardItem1.Title, BoardItem2.Title) |
| 52 |
else if SortIndex = 1 then |
| 53 |
Result := CompareInt(BoardItem1.Count, BoardItem2.Count) |
| 54 |
else |
| 55 |
Result := CompareDate(BoardItem1.RoundDate, BoardItem2.RoundDate); |
| 56 |
|
| 57 |
if not SortOrder then |
| 58 |
Result := Result * -1; |
| 59 |
end; |
| 60 |
|
| 61 |
function ThreadItemSortProc(List: TStringList; Item1, Item2: Integer): integer; |
| 62 |
var |
| 63 |
ThreadItem1: TThreadItem; |
| 64 |
ThreadItem2: TThreadItem; |
| 65 |
begin |
| 66 |
ThreadItem1 := TThreadItem(List.Objects[ Item1 ]); |
| 67 |
ThreadItem2 := TThreadItem(List.Objects[ Item2 ]); |
| 68 |
case SortIndex of |
| 69 |
0: |
| 70 |
begin |
| 71 |
if SortNoFlag then |
| 72 |
Result := CompareInt(ThreadItem1.No, ThreadItem2.No) |
| 73 |
else |
| 74 |
Result := AnsiCompareText(ThreadItem1.Title, ThreadItem2.Title) |
| 75 |
end; |
| 76 |
1: Result := CompareInt(ThreadItem1.AllResCount, ThreadItem2.AllResCount); |
| 77 |
2: |
| 78 |
begin |
| 79 |
if SortNonAcquiredCountFlag then |
| 80 |
if ThreadItem1.IsLogFile and ThreadItem2.IsLogFile then |
| 81 |
Result := CompareInt(ThreadItem1.AllResCount - ThreadItem1.Count, ThreadItem2.AllResCount - ThreadItem2.Count) |
| 82 |
else if ThreadItem1.IsLogFile then |
| 83 |
Result := 1 |
| 84 |
else if ThreadItem2.IsLogFile then |
| 85 |
Result := -1 |
| 86 |
else |
| 87 |
Result := 0 |
| 88 |
else |
| 89 |
Result := CompareInt(ThreadItem1.Count, ThreadItem2.Count); |
| 90 |
end; |
| 91 |
3: Result := CompareInt(ThreadItem1.NewResCount, ThreadItem2.NewResCount); |
| 92 |
4: Result := 0; |
| 93 |
5: Result := AnsiCompareText(ThreadItem1.RoundName, ThreadItem2.RoundName); |
| 94 |
6: Result := CompareDateTime(ThreadItem1.RoundDate, ThreadItem2.RoundDate); |
| 95 |
7: Result := CompareDateTime(ThreadItem1.CreateDate, ThreadItem2.CreateDate); |
| 96 |
else |
| 97 |
Result := 0; |
| 98 |
end; |
| 99 |
|
| 100 |
{ if SortIndex = 0 then |
| 101 |
if SortNoFlag then |
| 102 |
Result := CompareInt(ThreadItem1.No, ThreadItem2.No) |
| 103 |
else |
| 104 |
Result := CompareText(ThreadItem1.Title, ThreadItem2.Title) |
| 105 |
else if SortIndex = 1 then |
| 106 |
Result := CompareInt(ThreadItem1.Count, ThreadItem2.Count) |
| 107 |
else if SortIndex = 2 then |
| 108 |
// Result := CompareInt(ThreadItem1.RoundNo, ThreadItem2.RoundNo) |
| 109 |
Result := CompareText(ThreadItem1.RoundName, ThreadItem2.RoundName) |
| 110 |
else |
| 111 |
Result := CompareDate(ThreadItem1.LastModified, ThreadItem2.LastModified); |
| 112 |
} |
| 113 |
if not SortOrder then |
| 114 |
Result := Result * -1; |
| 115 |
end; |
| 116 |
|
| 117 |
function CompareBool(Item1, Item2: Boolean): Integer; |
| 118 |
begin |
| 119 |
if (Item1 = True) and (Item2 = False) then |
| 120 |
Result := 1 |
| 121 |
else if (Item2 = False) and (Item2 = True) then |
| 122 |
Result := -1 |
| 123 |
else |
| 124 |
Result := 0; |
| 125 |
end; |
| 126 |
|
| 127 |
function CompareInt(Item1, Item2: Integer): Integer; |
| 128 |
begin |
| 129 |
if Item1 > Item2 then |
| 130 |
Result := 1 |
| 131 |
else if Item1 < Item2 then |
| 132 |
Result := -1 |
| 133 |
else |
| 134 |
Result := 0; |
| 135 |
end; |
| 136 |
|
| 137 |
function CompareDate(Item1, Item2: TDateTime): Integer; |
| 138 |
begin |
| 139 |
if Item1 > Item2 then |
| 140 |
Result := 1 |
| 141 |
else if Item1 < Item2 then |
| 142 |
Result := -1 |
| 143 |
else |
| 144 |
Result := 0; |
| 145 |
end; |
| 146 |
|
| 147 |
end. |