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.8 - (hide annotations) (download) (as text)
Tue Jun 20 15:18:03 2006 UTC (17 years, 10 months ago) by h677
Branch: MAIN
CVS Tags: v1_52_0_660
Changes since 1.7: +21 -0 lines
File MIME type: text/x-pascal
バタ52の方の修正分をマージ

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 h677 1.4 // ini?t?@?C???????纏?????A?f?t?H???g?????l?[?????辿
124     if not FileExists(FilePath) then begin
125 h677 1.6 CopyFile(
126     PChar(ChangeFileExt(FilePath, '.default')),
127     PChar(FilePath), True);
128 h677 1.4 end;
129    
130 h677 1.1 // ?t?@?C???????????m?F
131     if FileExists(FilePath) then begin
132     ini := TMemIniFile.Create(FilePath);
133     sections := TStringList.Create;
134     keys := TStringList.Create;
135     try
136     ini.ReadSections(sections);
137    
138     for i :=0 to sections.Count - 1 do begin
139     keys.Clear;
140     ini.ReadSection(sections[i], keys);
141     for j := 0 to keys.Count - 1 do begin
142     resWord := TResistWord.Create;
143     resWord.SetCategory(sections[i]);
144     resWord.SetKey(keys[j]);
145     resWord.SetText(ini.ReadString(sections[i], keys[j], ''));
146     FDictionary.AddObject(resWord.GetKey, resWord);
147     end;
148     end;
149     finally
150     keys.Free;
151     sections.Free;
152     ini.Free;
153     end;
154 h677 1.7 if FSorted Then begin
155     FDictionary.CustomSort(KeySort);
156     end;
157 h677 1.1 end;
158    
159     except
160     FInit := False;
161     end;
162     end;
163     //! ?w?????????p?X???t?@?C?????徹?????辿
164     procedure TInputAssistDM.SaveToFile(FilePath: String);
165     var
166     ini : TMemIniFile;
167     i : Integer;
168     resWord : TResistWord;
169     begin
170     if FileExists(FilePath) then begin
171     try
172 h677 1.6 SysUtils.DeleteFile(FilePath);
173 h677 1.1 except
174     end;
175     end;
176 h677 1.7
177 h677 1.1 ini := TMemIniFile.Create(FilePath);
178     try
179     for i :=0 to FDictionary.Count - 1 do begin
180     resWord := TResistWord(FDictionary.Objects[i]);
181     ini.WriteString(resWord.FCategory, resWord.FKey, resWord.FText);
182     end;
183     ini.UpdateFile;
184     finally
185     ini.Free;
186     end;
187     end;
188     //! ?f?X?g???N?^
189     procedure TInputAssistDM.DataModuleDestroy(Sender: TObject);
190     var
191     i : Integer;
192     begin
193     if (FDictionary <> nil) then begin
194     for i := FDictionary.Count - 1 downto 0 do begin
195     TResistWord(FDictionary.Objects[i]).Free;
196     end;
197     FDictionary.Clear;
198     FDictionary.Capacity := 0;
199     FDictionary.Free;
200     end;
201     end;
202     //! ?R???X?g???N?^
203     procedure TInputAssistDM.DataModuleCreate(Sender: TObject);
204     begin
205     FDictionary := TStringList.Create;
206 h677 1.7 FDictionary.Sorted := False;
207     FSorted := True;
208 h677 1.1 end;
209     //! ?o?^?P???????転
210     function TInputAssistDM.ResistWordCount : Integer;
211     begin
212     Result := 0;
213     if (FDictionary <> nil) then begin
214     Result := FDictionary.Count;
215     end;
216     end;
217     //! ?o?^?P?????転
218     function TInputAssistDM.GetResistWord(Index: Integer): TResistWord;
219     begin
220     Result := nil;
221     if (FDictionary <> nil) then begin
222     if (Index >= 0) and (Index < FDictionary.Count) then begin
223     Result := TResistWord(FDictionary.Objects[index]);
224     end;
225     end;
226     end;
227     //! ?o?^?P?????鱈??
228     procedure TInputAssistDM.DeleteResistWord(ResistWord: TResistWord);
229     var
230     i : Integer;
231     begin
232     if (FDictionary <> nil) then begin
233     for i := 0 to FDictionary.Count - 1 do begin
234     if (ResistWord = FDictionary.Objects[i]) then begin
235     TResistWord(FDictionary.Objects[i]).Free;
236     FDictionary.Delete(i);
237     break;
238     end;
239     end;
240 h677 1.7 if FSorted Then begin
241     FDictionary.CustomSort(KeySort);
242     end;
243 h677 1.1 end;
244     end;
245     //! ?o?^?P??????
246     function TInputAssistDM.Add(Key: String): TResistWord;
247     var
248     resWord : TResistWord;
249     begin
250     Result := nil;
251     if (FDictionary <> nil) then begin
252     resWord := TResistWord.Create;
253     resWord.SetKey(Key);
254     resWord.SetCategory('?J?e?S??');
255     resWord.SetText('???^??');
256     FDictionary.AddObject(Key, resWord);
257     Result := resWord;
258 h677 1.7 if FSorted Then begin
259     FDictionary.CustomSort(KeySort);
260     end;
261 h677 1.1 end;
262     end;
263     //! ?o?^?P?????L?[???X
264     procedure TInputAssistDM.ChangeKey(ResistWord: TResistWord);
265     var
266     i : Integer;
267     begin
268     if (FDictionary <> nil) then begin
269     for i := 0 to FDictionary.Count - 1 do begin
270     if (ResistWord = FDictionary.Objects[i]) then begin
271     FDictionary.Strings[i] := ResistWord.GetKey;
272     break;
273     end;
274     end;
275 h677 1.7 if FSorted Then begin
276     FDictionary.CustomSort(KeySort);
277     end;
278    
279 h677 1.1 end;
280     end;
281     //! Key???????o?^?????????辿?P???????転
282     function TInputAssistDM.GetStartWithKeyResistWords(Key: String; var list: TStringList): Integer;
283     var
284     i : Integer;
285     resWord : TResistWord;
286    
287     begin
288     Result := 0;
289     if (FDictionary <> nil) and (list <> nil) then begin
290     Key := ZenToHan(Key);
291     for i := 0 to FDictionary.Count - 1 do begin
292     if (AnsiPos(Key, ZenToHan(FDictionary.Strings[i])) = 1) then begin
293     Inc(Result);
294     resWord := TResistWord(FDictionary.Objects[i]);
295     list.AddObject(resWord.GetKey + '(' +
296     resWord.GetCategory + ')', resWord);
297     end else if (Result > 0) then begin
298     //?\?[?g?????????辿???巽?A?q?b?g???????A?????辿???存
299     break;
300     end;
301     end;
302     end;
303     end;
304     //! Key???J?e?S?????????o?^?????????辿?P???????転
305     function TInputAssistDM.GetStartWithCategoryResistWords(Key: String; var list: TStringList): Integer;
306     var
307     i : Integer;
308     resWord : TResistWord;
309     begin
310     Result := 0;
311     if (FDictionary <> nil) and (list <> nil) then begin
312     Key := ZenToHan(Key);
313     for i := 0 to FDictionary.Count - 1 do begin
314     resWord := TResistWord(FDictionary.Objects[i]);
315     if (AnsiPos(Key, ZenToHan(resWord.GetCategory)) = 1) then begin
316     Inc(Result);
317     list.AddObject(resWord.GetKey + '(' +
318     resWord.GetCategory + ')', resWord);
319     end;
320     end;
321 h677 1.2 list.CustomSort(CategorySort);
322 h677 1.1 end;
323     end;
324 h677 1.2
325 h677 1.1 //! ?\?[?g???坦???????転
326     function TInputAssistDM.GetSorted: Boolean;
327     begin
328 h677 1.7 Result := FSorted;
329 h677 1.1 end;
330     //! ?\?[?g?坦????????
331     procedure TInputAssistDM.SetSorted(Value: Boolean);
332     begin
333 h677 1.7 if (not FSorted) and (Value) then begin
334     FDictionary.CustomSort(KeySort);
335 h677 1.1 end;
336 h677 1.7 FSorted := Value;
337 h677 1.1 end;
338 h677 1.3 //! Key???J?e?S?????o?^?????????辿?P???????転
339     function TInputAssistDM.GetCategoryResistWords(Key: String; var list: TStringList): Integer;
340     var
341     i : Integer;
342     resWord : TResistWord;
343     begin
344     Result := 0;
345     if (FDictionary <> nil) and (list <> nil) then begin
346     for i := 0 to FDictionary.Count - 1 do begin
347     resWord := TResistWord(FDictionary.Objects[i]);
348     if (Key = resWord.GetCategory) then begin
349     Inc(Result);
350     list.AddObject(resWord.GetKey + '(' +
351     resWord.GetCategory + ')', resWord);
352     end;
353     end;
354     list.CustomSort(CategorySort);
355     end;
356     end;
357    
358     //! ?o?^?????L?[???S?????J?e?S?????X?g???転
359     procedure TInputAssistDM.GetCategoryList(var list: TStringList);
360     var
361     i : Integer;
362     begin
363     if (FDictionary <> nil) and (list <> nil) then begin
364     // ?d???`?F?b?N??TStringList???@?\?長?s?造
365     list.Clear;
366     list.Duplicates := dupIgnore;
367     list.Sorted := true;
368     list.BeginUpdate;
369     for i := 0 to FDictionary.Count - 1 do begin
370     list.Add(TResistWord(FDictionary.Objects[i]).GetCategory);
371     end;
372     list.EndUpdate;
373     end;
374     end;
375 h677 1.1
376 h677 1.2 //! Key???J?e?S?????????o?^?P?????????????\?[?g?p?辰?r???\?b?h
377     function CategorySort(List: TStringList; Index1, Index2: Integer): Integer;
378     var
379     resWord1 : TResistWord;
380     resWord2 : TResistWord;
381     begin
382     Result := 0;
383     try
384     resWord1 := TResistWord(List.Objects[Index1]);
385     resWord2 := TResistWord(List.Objects[Index2]);
386 h677 1.7 Result := CompareStr(ZenToHan(resWord1.GetCategory),
387     ZenToHan(resWord2.GetCategory));
388     if (Result = 0) then begin
389     Result := CompareStr(ZenToHan(resWord1.GetKey),
390     ZenToHan(resWord2.GetKey));
391     end;
392     except
393     end;
394     end;
395     //! Key???S?添?p???????`?長?\?[?g???辿?徹???辰?r???\?b?h
396     function KeySort(List: TStringList; Index1, Index2: Integer): Integer;
397     var
398     resWord1 : TResistWord;
399     resWord2 : TResistWord;
400     begin
401     Result := 0;
402     try
403     resWord1 := TResistWord(List.Objects[Index1]);
404     resWord2 := TResistWord(List.Objects[Index2]);
405     Result := CompareStr(ZenToHan(resWord1.FKey),
406     ZenToHan(resWord2.FKey));
407 h677 1.2 if (Result = 0) then begin
408 h677 1.7 Result := CompareStr(ZenToHan(resWord1.GetCategory),
409     ZenToHan(resWord2.GetCategory));
410 h677 1.2 end;
411     except
412     end;
413     end;
414 h677 1.8 //! ?哲???o?^???????L?[???J?e?S?????Z?b?g?????造???`?F?b?N
415     function TInputAssistDM.IsDupulicate(Key: String; Category: String): Boolean;
416     var
417     i : Integer;
418     resWord : TResistWord;
419     begin
420     // ???????\?b?h?長???A?\?[?g???????????巽???????長?A?S?????L?[???T???直?????辿
421     Result := False;
422     if (FDictionary <> nil) then begin
423     for i := 0 to FDictionary.Count - 1 do begin
424     if (Key = FDictionary.Strings[i]) and
425     (Category = TResistWord(FDictionary.Objects[i]).GetCategory)
426     then begin
427     Result := True;
428     Break;
429     end;
430     end;
431     end;
432     end;
433 h677 1.2
434 h677 1.1 end.

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