Develop and Download Open Source Software

Browse CVS Repository

Annotation of /gikonavigoeson/gikonavi/InputAssistDataModule.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (hide annotations) (download) (as text)
Mon Jul 3 14:49:07 2006 UTC (17 years, 9 months ago) by h677
Branch: MAIN
CVS Tags: v1_53_0_671, v1_54_0_677, v1_54_0_676, v1_54_0_678, v1_56_0_707, v1_56_0_705, v1_56_0_704, v1_56_0_703, v1_56_0_702, v1_56_0_701, v1_56_0_700, v1_54_0_687, v1_56_0_710, v1_56_0_711, v1_54_0_688, v1_54_0_689, v1_54_0_684, v1_54_0_685, v1_53_0_664, v1_53_0_665, v1_53_0_667, v1_53_0_666, v1_53_0_669, v1_53_0_668, v1_55_0_692, v1_55_0_693, v1_55_0_696, v1_55_0_697, v1_55_0_694, v1_55_0_695, v1_54_1_691, v1_55_1_697, v1_56_0_714, v1_53_0_672, v1_53_0_670, v1_54_0_686, v1_54_0_680, v1_54_0_681, v1_56_0_712, v1_56_0_713, v1_54_0_682, v1_54_0_683, v1_54_0_679, marged_bRESPOPUP, v1_54_0_675, v1_56_0_706, root-of-Bb53, v1_54_0_674, v1_54_0_690, v1_56_0_709, v1_56_0_708, v1_53_1_673, v1_56_0_699, v1_56_0_698
Branch point for: Bb55, Bb53, bRESPOPUP, bListSU, Bb54
Changes since 1.9: +1 -8 lines
File MIME type: text/x-pascal
内部でデフォルトファイルを操作しなくした

1 h677 1.1 unit InputAssistDataModule;
2    
3     interface
4    
5     uses
6 h677 1.6 SysUtils, Classes, Windows;
7 h677 1.1
8     type
9     TResistWord = class;
10    
11     TInputAssistDM = class(TDataModule)
12     procedure DataModuleDestroy(Sender: TObject);
13     procedure DataModuleCreate(Sender: TObject);
14     private
15     { Private ?辿?転 }
16     FInit : Boolean;
17     FDictionary : TStringList; ///< ?o?^?P???????^?????鼎??
18 h677 1.7 FSorted : Boolean;
19 h677 1.1 function GetSorted: Boolean; ///< ?\?[?g???坦???????転
20     procedure SetSorted(Value: Boolean); ///< ?\?[?g?坦????????
21 h677 1.2
22 h677 1.1 public
23     { Public ?辿?転 }
24     property Sorted : Boolean read GetSorted write SetSorted;
25     procedure Init(FilePath: String);
26     procedure SaveToFile(FilePath: String);
27     function ResistWordCount : Integer; ///<?o?^?P???????転
28     function GetResistWord(Index: Integer): TResistWord; ///< ?o?^?P?????転
29     procedure DeleteResistWord(ResistWord: TResistWord); ///< ?o?^?P?????鱈??
30     function Add(Key: String): TResistWord; ///< ?o?^?P??????
31     procedure ChangeKey(ResistWord: TResistWord); ///< ?o?^?P?????L?[???X
32     //! Key???L?[???????o?^?????????辿?P???????転
33     function GetStartWithKeyResistWords(Key: String; var list: TStringList): Integer;
34     //! Key???J?e?S?????????o?^?????????辿?P???????転
35     function GetStartWithCategoryResistWords(Key: String; var list: TStringList): Integer;
36 h677 1.3 //! Key???J?e?S?????o?^?????????辿?P???????転
37     function GetCategoryResistWords(Key: String; var list: TStringList): Integer;
38     //! ?o?^?????L?[???S?????J?e?S?????X?g???転
39     procedure GetCategoryList(var list: TStringList);
40 h677 1.8 //! ?哲???o?^???????L?[???J?e?S?????Z?b?g?????造???`?F?b?N
41     function IsDupulicate(Key: String; Category: String): Boolean;
42 h677 1.3
43 h677 1.1 end;
44    
45     TResistWord = class(TObject)
46     private
47     FKey : String; ///< ?????????L?[?????辿
48     FCategory : String; ///< ???鄭
49     FText : String; ///< ???^??
50     public
51     function GetKey: String;
52     procedure SetKey(Value: String);
53     function GetCategory: String;
54     procedure SetCategory(Value: String);
55     function GetText: String;
56     procedure SetText(Value: String);
57     property Key: String read FKey write FKey;
58     property Category: String read FCategory write FCategory;
59     property Text: String read GetText write SetText;
60     end;
61 h677 1.2
62     function CategorySort(List: TStringList; Index1, Index2: Integer): Integer;
63 h677 1.7 function KeySort(List: TStringList; Index1, Index2: Integer): Integer;
64 h677 1.1 var
65     InputAssistDM: TInputAssistDM;
66    
67     implementation
68    
69     uses
70     MojuUtils, IniFiles;
71    
72     {$R *.dfm}
73     //! FKey???????????????辿?l?????転???辿
74     function TResistWord.GetKey: String;
75     begin
76     //?G?X?P?[?v?直?????辿=?????????辿
77     Result := MojuUtils.CustomStringReplace(FKey, '&#61;', '=');
78     end;
79     //! FKey???l?????????辿
80     procedure TResistWord.SetKey(Value: String);
81     begin
82     //=???徹???????g?造???長?G?X?P?[?v???辿
83     FKey := MojuUtils.CustomStringReplace(Value, '=', '&#61;');
84     end;
85     //! FCategory???????????????辿?l?????転???辿
86     function TResistWord.GetCategory: String;
87     begin
88     //?G?X?P?[?v?直?????辿=?????????辿
89     Result := MojuUtils.CustomStringReplace(FCategory, '&#61;', '=');
90     end;
91     //! FCategory???l?????????辿
92     procedure TResistWord.SetCategory(Value: String);
93     begin
94     //=???徹???????g?造???長?G?X?P?[?v???辿
95     FCategory := MojuUtils.CustomStringReplace(Value, '=', '&#61;');
96     end;
97     //! FText???????????????辿?l?????転???辿
98     function TResistWord.GetText: String;
99     begin
100     //?G?X?P?[?v?直?????辿=?????????辿
101     Result := MojuUtils.CustomStringReplace(FText, '&#61;', '=');
102     // #1???直???端?s?R?[?h??#13#10?????????辿
103     Result := MojuUtils.CustomStringReplace(Result, #1, #13#10);
104     end;
105     procedure TResistWord.SetText(Value: String);
106     begin
107     //=???徹???????g?造???長?G?X?P?[?v???辿
108     FText := MojuUtils.CustomStringReplace(Value, '=', '&#61;');
109     //?端?s?R?[?h??#1?????辿?i1?s?????辿????)
110     FText := MojuUtils.CustomStringReplace(FText, #13#10, #1);
111     end;
112     //! ?t?@?C?????????????長???炭?泥???辿
113     procedure TInputAssistDM.Init(FilePath: String);
114     var
115     ini : TMemIniFile;
116     sections: TStringList;
117     keys: TStringList;
118     i, j : Integer;
119     resWord : TResistWord;
120     begin
121     FInit := True;
122     try
123     // ?t?@?C???????????m?F
124     if FileExists(FilePath) then begin
125 h677 1.10 ini := TMemIniFile.Create(FilePath);
126 h677 1.1 sections := TStringList.Create;
127     keys := TStringList.Create;
128     try
129     ini.ReadSections(sections);
130    
131     for i :=0 to sections.Count - 1 do begin
132     keys.Clear;
133     ini.ReadSection(sections[i], keys);
134     for j := 0 to keys.Count - 1 do begin
135     resWord := TResistWord.Create;
136     resWord.SetCategory(sections[i]);
137     resWord.SetKey(keys[j]);
138     resWord.SetText(ini.ReadString(sections[i], keys[j], ''));
139     FDictionary.AddObject(resWord.GetKey, resWord);
140     end;
141     end;
142     finally
143     keys.Free;
144     sections.Free;
145     ini.Free;
146     end;
147 h677 1.7 if FSorted Then begin
148     FDictionary.CustomSort(KeySort);
149     end;
150 h677 1.1 end;
151    
152     except
153     FInit := False;
154     end;
155     end;
156     //! ?w?????????p?X???t?@?C?????徹?????辿
157     procedure TInputAssistDM.SaveToFile(FilePath: String);
158     var
159     ini : TMemIniFile;
160     i : Integer;
161     resWord : TResistWord;
162     begin
163     if FileExists(FilePath) then begin
164     try
165 h677 1.6 SysUtils.DeleteFile(FilePath);
166 h677 1.1 except
167     end;
168     end;
169 h677 1.7
170 h677 1.1 ini := TMemIniFile.Create(FilePath);
171     try
172     for i :=0 to FDictionary.Count - 1 do begin
173     resWord := TResistWord(FDictionary.Objects[i]);
174     ini.WriteString(resWord.FCategory, resWord.FKey, resWord.FText);
175     end;
176     ini.UpdateFile;
177     finally
178     ini.Free;
179     end;
180     end;
181     //! ?f?X?g???N?^
182     procedure TInputAssistDM.DataModuleDestroy(Sender: TObject);
183     var
184     i : Integer;
185     begin
186     if (FDictionary <> nil) then begin
187     for i := FDictionary.Count - 1 downto 0 do begin
188     TResistWord(FDictionary.Objects[i]).Free;
189     end;
190     FDictionary.Clear;
191     FDictionary.Capacity := 0;
192     FDictionary.Free;
193     end;
194     end;
195     //! ?R???X?g???N?^
196     procedure TInputAssistDM.DataModuleCreate(Sender: TObject);
197     begin
198     FDictionary := TStringList.Create;
199 h677 1.7 FDictionary.Sorted := False;
200     FSorted := True;
201 h677 1.1 end;
202     //! ?o?^?P???????転
203     function TInputAssistDM.ResistWordCount : Integer;
204     begin
205     Result := 0;
206     if (FDictionary <> nil) then begin
207     Result := FDictionary.Count;
208     end;
209     end;
210     //! ?o?^?P?????転
211     function TInputAssistDM.GetResistWord(Index: Integer): TResistWord;
212     begin
213     Result := nil;
214     if (FDictionary <> nil) then begin
215     if (Index >= 0) and (Index < FDictionary.Count) then begin
216     Result := TResistWord(FDictionary.Objects[index]);
217     end;
218     end;
219     end;
220     //! ?o?^?P?????鱈??
221     procedure TInputAssistDM.DeleteResistWord(ResistWord: TResistWord);
222     var
223     i : Integer;
224     begin
225     if (FDictionary <> nil) then begin
226     for i := 0 to FDictionary.Count - 1 do begin
227     if (ResistWord = FDictionary.Objects[i]) then begin
228     TResistWord(FDictionary.Objects[i]).Free;
229     FDictionary.Delete(i);
230     break;
231     end;
232     end;
233 h677 1.7 if FSorted Then begin
234     FDictionary.CustomSort(KeySort);
235     end;
236 h677 1.1 end;
237     end;
238     //! ?o?^?P??????
239     function TInputAssistDM.Add(Key: String): TResistWord;
240     var
241     resWord : TResistWord;
242     begin
243     Result := nil;
244     if (FDictionary <> nil) then begin
245     resWord := TResistWord.Create;
246     resWord.SetKey(Key);
247     resWord.SetCategory('?J?e?S??');
248     resWord.SetText('???^??');
249     FDictionary.AddObject(Key, resWord);
250     Result := resWord;
251 h677 1.7 if FSorted Then begin
252     FDictionary.CustomSort(KeySort);
253     end;
254 h677 1.1 end;
255     end;
256     //! ?o?^?P?????L?[???X
257     procedure TInputAssistDM.ChangeKey(ResistWord: TResistWord);
258     var
259     i : Integer;
260     begin
261     if (FDictionary <> nil) then begin
262     for i := 0 to FDictionary.Count - 1 do begin
263     if (ResistWord = FDictionary.Objects[i]) then begin
264     FDictionary.Strings[i] := ResistWord.GetKey;
265     break;
266     end;
267     end;
268 h677 1.7 if FSorted Then begin
269     FDictionary.CustomSort(KeySort);
270     end;
271    
272 h677 1.1 end;
273     end;
274     //! Key???????o?^?????????辿?P???????転
275     function TInputAssistDM.GetStartWithKeyResistWords(Key: String; var list: TStringList): Integer;
276     var
277     i : Integer;
278     resWord : TResistWord;
279    
280     begin
281     Result := 0;
282     if (FDictionary <> nil) and (list <> nil) then begin
283     Key := ZenToHan(Key);
284     for i := 0 to FDictionary.Count - 1 do begin
285     if (AnsiPos(Key, ZenToHan(FDictionary.Strings[i])) = 1) then begin
286     Inc(Result);
287     resWord := TResistWord(FDictionary.Objects[i]);
288     list.AddObject(resWord.GetKey + '(' +
289     resWord.GetCategory + ')', resWord);
290     end else if (Result > 0) then begin
291     //?\?[?g?????????辿???巽?A?q?b?g???????A?????辿???存
292     break;
293     end;
294     end;
295     end;
296     end;
297     //! Key???J?e?S?????????o?^?????????辿?P???????転
298     function TInputAssistDM.GetStartWithCategoryResistWords(Key: String; var list: TStringList): Integer;
299     var
300     i : Integer;
301     resWord : TResistWord;
302     begin
303     Result := 0;
304     if (FDictionary <> nil) and (list <> nil) then begin
305     Key := ZenToHan(Key);
306     for i := 0 to FDictionary.Count - 1 do begin
307     resWord := TResistWord(FDictionary.Objects[i]);
308     if (AnsiPos(Key, ZenToHan(resWord.GetCategory)) = 1) then begin
309     Inc(Result);
310     list.AddObject(resWord.GetKey + '(' +
311     resWord.GetCategory + ')', resWord);
312     end;
313     end;
314 h677 1.2 list.CustomSort(CategorySort);
315 h677 1.1 end;
316     end;
317 h677 1.2
318 h677 1.1 //! ?\?[?g???坦???????転
319     function TInputAssistDM.GetSorted: Boolean;
320     begin
321 h677 1.7 Result := FSorted;
322 h677 1.1 end;
323     //! ?\?[?g?坦????????
324     procedure TInputAssistDM.SetSorted(Value: Boolean);
325     begin
326 h677 1.7 if (not FSorted) and (Value) then begin
327     FDictionary.CustomSort(KeySort);
328 h677 1.1 end;
329 h677 1.7 FSorted := Value;
330 h677 1.1 end;
331 h677 1.3 //! Key???J?e?S?????o?^?????????辿?P???????転
332     function TInputAssistDM.GetCategoryResistWords(Key: String; var list: TStringList): Integer;
333     var
334     i : Integer;
335     resWord : TResistWord;
336     begin
337     Result := 0;
338     if (FDictionary <> nil) and (list <> nil) then begin
339     for i := 0 to FDictionary.Count - 1 do begin
340     resWord := TResistWord(FDictionary.Objects[i]);
341     if (Key = resWord.GetCategory) then begin
342     Inc(Result);
343     list.AddObject(resWord.GetKey + '(' +
344     resWord.GetCategory + ')', resWord);
345     end;
346     end;
347     list.CustomSort(CategorySort);
348     end;
349     end;
350    
351     //! ?o?^?????L?[???S?????J?e?S?????X?g???転
352     procedure TInputAssistDM.GetCategoryList(var list: TStringList);
353     var
354     i : Integer;
355     begin
356     if (FDictionary <> nil) and (list <> nil) then begin
357     // ?d???`?F?b?N??TStringList???@?\?長?s?造
358     list.Clear;
359     list.Duplicates := dupIgnore;
360     list.Sorted := true;
361     list.BeginUpdate;
362     for i := 0 to FDictionary.Count - 1 do begin
363     list.Add(TResistWord(FDictionary.Objects[i]).GetCategory);
364     end;
365     list.EndUpdate;
366     end;
367     end;
368 h677 1.1
369 h677 1.2 //! Key???J?e?S?????????o?^?P?????????????\?[?g?p?辰?r???\?b?h
370     function CategorySort(List: TStringList; Index1, Index2: Integer): Integer;
371     var
372     resWord1 : TResistWord;
373     resWord2 : TResistWord;
374     begin
375     Result := 0;
376     try
377     resWord1 := TResistWord(List.Objects[Index1]);
378     resWord2 := TResistWord(List.Objects[Index2]);
379 h677 1.7 Result := CompareStr(ZenToHan(resWord1.GetCategory),
380     ZenToHan(resWord2.GetCategory));
381     if (Result = 0) then begin
382     Result := CompareStr(ZenToHan(resWord1.GetKey),
383     ZenToHan(resWord2.GetKey));
384     end;
385     except
386     end;
387     end;
388     //! Key???S?添?p???????`?長?\?[?g???辿?徹???辰?r???\?b?h
389     function KeySort(List: TStringList; Index1, Index2: Integer): Integer;
390     var
391     resWord1 : TResistWord;
392     resWord2 : TResistWord;
393     begin
394     Result := 0;
395     try
396     resWord1 := TResistWord(List.Objects[Index1]);
397     resWord2 := TResistWord(List.Objects[Index2]);
398     Result := CompareStr(ZenToHan(resWord1.FKey),
399     ZenToHan(resWord2.FKey));
400 h677 1.2 if (Result = 0) then begin
401 h677 1.7 Result := CompareStr(ZenToHan(resWord1.GetCategory),
402     ZenToHan(resWord2.GetCategory));
403 h677 1.2 end;
404     except
405     end;
406     end;
407 h677 1.8 //! ?哲???o?^???????L?[???J?e?S?????Z?b?g?????造???`?F?b?N
408     function TInputAssistDM.IsDupulicate(Key: String; Category: String): Boolean;
409     var
410     i : Integer;
411 h677 1.9 // resWord : TResistWord;
412 h677 1.8 begin
413     // ???????\?b?h?長???A?\?[?g???????????巽???????長?A?S?????L?[???T???直?????辿
414     Result := False;
415     if (FDictionary <> nil) then begin
416     for i := 0 to FDictionary.Count - 1 do begin
417     if (Key = FDictionary.Strings[i]) and
418     (Category = TResistWord(FDictionary.Objects[i]).GetCategory)
419     then begin
420     Result := True;
421     Break;
422     end;
423     end;
424     end;
425     end;
426 h677 1.2
427 h677 1.1 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26