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