OSDN Git Service

(none)
[gikonavigoeson/gikonavi.git] / Sort.pas
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(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 := CompareDateTime(ThreadItem1.RoundDate, ThreadItem2.RoundDate);
81         7: Result := CompareDateTime(ThreadItem1.CreateDate, ThreadItem2.CreateDate);
82     else
83         Result := 0;
84         end;
85
86 {       if SortIndex = 0 then
87                 if SortNoFlag then
88                         Result := CompareInt(ThreadItem1.No, ThreadItem2.No)
89                 else
90                         Result := CompareText(ThreadItem1.Title, ThreadItem2.Title)
91         else if SortIndex = 1 then
92                 Result := CompareInt(ThreadItem1.Count, ThreadItem2.Count)
93         else if SortIndex = 2 then
94 //              Result := CompareInt(ThreadItem1.RoundNo, ThreadItem2.RoundNo)
95                 Result := CompareText(ThreadItem1.RoundName, ThreadItem2.RoundName)
96         else
97                 Result := CompareDate(ThreadItem1.LastModified, ThreadItem2.LastModified);
98 }
99         if not SortOrder then
100                 Result := Result * -1;
101 end;
102
103 function CompareBool(Item1, Item2: Boolean): Integer;
104 begin
105         if (Item1 = True) and (Item2 = False) then
106                 Result := 1
107         else if (Item2 = False) and (Item2 = True) then
108                 Result := -1
109         else
110                 Result := 0;
111 end;
112
113 function CompareInt(Item1, Item2: Integer): Integer;
114 begin
115         if Item1 > Item2 then
116                 Result := 1
117         else if Item1 < Item2 then
118                 Result := -1
119         else
120                 Result := 0;
121 end;
122
123 function CompareDate(Item1, Item2: TDateTime): Integer;
124 begin
125         if Item1 > Item2 then
126                 Result := 1
127         else if Item1 < Item2 then
128                 Result := -1
129         else
130                 Result := 0;
131 end;
132
133 end.