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.2 - (hide annotations) (download) (as text)
Sun Jan 15 16:44:50 2006 UTC (18 years, 3 months ago) by h677
Branch: MAIN
CVS Tags: v1_52_0_644, v1_52_0_643, v1_52_0_642
Changes since 1.1: +23 -0 lines
File MIME type: text/x-pascal
・ォ・ニ・エ・熙ヌシ隍?ネ、ュ、ヒ・ォ・ニ・エ・熙ヌ・ス。シ・ネ、ケ、?隍ヲ、ヒハムケケ。」

1 h677 1.1 unit InputAssistDataModule;
2    
3     interface
4    
5     uses
6     SysUtils, Classes;
7    
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; ///< ツ登ツ録ツ単ツ呼卍て?墜債型ツ頁崢て堋芝、ツ渉?/span>
18     function GetSorted: Boolean; ///< ツソツーツトツて堋湘ウツ妥板て堋柴?毒セ
19     procedure SetSorted(Value: Boolean); ///< ツソツーツトツ湘ウツ妥板て堋静敖墜?/span>
20 h677 1.2
21 h677 1.1 public
22     { Public ツ静ゥツ固セ }
23     property Sorted : Boolean read GetSorted write SetSorted;
24     procedure Init(FilePath: String);
25     procedure SaveToFile(FilePath: String);
26     function ResistWordCount : Integer; ///<ツ登ツ録ツ単ツ呼卍青板柴?毒セ
27     function GetResistWord(Index: Integer): TResistWord; ///< ツ登ツ録ツ単ツ呼卍柴?毒セ
28     procedure DeleteResistWord(ResistWord: TResistWord); ///< ツ登ツ録ツ単ツ呼卍て堋催ュツ渉?/span>
29     function Add(Key: String): TResistWord; ///< ツ登ツ録ツ単ツ呼卍津?嘉?/span>
30     procedure ChangeKey(ResistWord: TResistWord); ///< ツ登ツ録ツ単ツ呼卍て堋キツーツ米篠更
31     //! Keyツて堕キツーツづ可篠敖づつ登ツ録ツでつて卍づ?ね伉づゥツ単ツ呼卍て堕柴?毒セ
32     function GetStartWithKeyResistWords(Key: String; var list: TStringList): Integer;
33     //! Keyツて堕カツテツゴツδ環づ可篠敖づつ登ツ録ツでつて卍づ?ね伉づゥツ単ツ呼卍て堕柴?毒セ
34     function GetStartWithCategoryResistWords(Key: String; var list: TStringList): Integer;
35     end;
36    
37     TResistWord = class(TObject)
38     private
39     FKey : String; ///< ツ米篠翰?篠楪て堋キツーツづ可て個づゥ
40     FCategory : String; ///< ツ頁楪稜「
41     FText : String; ///< ツ墜債型ツ頁?/span>
42     public
43     function GetKey: String;
44     procedure SetKey(Value: String);
45     function GetCategory: String;
46     procedure SetCategory(Value: String);
47     function GetText: String;
48     procedure SetText(Value: String);
49     property Key: String read FKey write FKey;
50     property Category: String read FCategory write FCategory;
51     property Text: String read GetText write SetText;
52     end;
53 h677 1.2
54     function CategorySort(List: TStringList; Index1, Index2: Integer): Integer;
55 h677 1.1 var
56     InputAssistDM: TInputAssistDM;
57    
58     implementation
59    
60     uses
61     MojuUtils, IniFiles;
62    
63     {$R *.dfm}
64     //! FKeyツづ可静敖墜債でつて卍づ?ね伉づゥツ値ツて堕柴?毒セツね?づゥ
65     function TResistWord.GetKey: String;
66     begin
67     //ツエツスツケツーツプツてセツづ?ね伉づゥ=ツて堕閉慊固つね?づゥ
68     Result := MojuUtils.CustomStringReplace(FKey, '&#61;', '=');
69     end;
70     //! FKeyツづ可値ツて堕静敖墜債ね?づゥ
71     procedure TResistWord.SetKey(Value: String);
72     begin
73     //=ツづ債頁ーツ打崢篠楪づ可使ツつ、ツて堋てケツエツスツケツーツプツね?づゥ
74     FKey := MojuUtils.CustomStringReplace(Value, '=', '&#61;');
75     end;
76     //! FCategoryツづ可静敖墜債でつて卍づ?ね伉づゥツ値ツて堕柴?毒セツね?づゥ
77     function TResistWord.GetCategory: String;
78     begin
79     //ツエツスツケツーツプツてセツづ?ね伉づゥ=ツて堕閉慊固つね?づゥ
80     Result := MojuUtils.CustomStringReplace(FCategory, '&#61;', '=');
81     end;
82     //! FCategoryツづ可値ツて堕静敖墜債ね?づゥ
83     procedure TResistWord.SetCategory(Value: String);
84     begin
85     //=ツづ債頁ーツ打崢篠楪づ可使ツつ、ツて堋てケツエツスツケツーツプツね?づゥ
86     FCategory := MojuUtils.CustomStringReplace(Value, '=', '&#61;');
87     end;
88     //! FTextツづ可静敖墜債でつて卍づ?ね伉づゥツ値ツて堕柴?毒セツね?づゥ
89     function TResistWord.GetText: String;
90     begin
91     //ツエツスツケツーツプツてセツづ?ね伉づゥ=ツて堕閉慊固つね?づゥ
92     Result := MojuUtils.CustomStringReplace(FText, '&#61;', '=');
93     // #1ツづ可てセツね敖嘉シツ行ツコツーツドツて?13#10ツづ可閉慊固つね?づゥ
94     Result := MojuUtils.CustomStringReplace(Result, #1, #13#10);
95     end;
96     procedure TResistWord.SetText(Value: String);
97     begin
98     //=ツづ債頁ーツ打崢篠楪づ可使ツつ、ツて堋てケツエツスツケツーツプツね?づゥ
99     FText := MojuUtils.CustomStringReplace(Value, '=', '&#61;');
100     //ツ嘉シツ行ツコツーツドツて?1ツづ可ね?づゥツ(1ツ行ツづ可ね?づゥツね敖づ?
101     FText := MojuUtils.CustomStringReplace(FText, #13#10, #1);
102     end;
103     //! ツフツァツイツδ仰て堕禿?づ敖債楪で?てケツ渉可甘コツ嫁・ツね?づゥ
104     procedure TInputAssistDM.Init(FilePath: String);
105     var
106     ini : TMemIniFile;
107     sections: TStringList;
108     keys: TStringList;
109     i, j : Integer;
110     resWord : TResistWord;
111     begin
112     FInit := True;
113     try
114     // ツフツァツイツδ仰て堋打崢催敖て堕確ツ認
115     if FileExists(FilePath) then begin
116     ini := TMemIniFile.Create(FilePath);
117     sections := TStringList.Create;
118     keys := TStringList.Create;
119     try
120     ini.ReadSections(sections);
121    
122     for i :=0 to sections.Count - 1 do begin
123     keys.Clear;
124     ini.ReadSection(sections[i], keys);
125     for j := 0 to keys.Count - 1 do begin
126     resWord := TResistWord.Create;
127     resWord.SetCategory(sections[i]);
128     resWord.SetKey(keys[j]);
129     resWord.SetText(ini.ReadString(sections[i], keys[j], ''));
130     FDictionary.AddObject(resWord.GetKey, resWord);
131     end;
132     end;
133     finally
134     keys.Free;
135     sections.Free;
136     ini.Free;
137     end;
138     end;
139    
140     except
141     FInit := False;
142     end;
143     end;
144     //! ツ指ツ墜債でつて卍ね敖パツスツて堋フツァツイツδ仰づ可頁ーツ打崢ね?づゥ
145     procedure TInputAssistDM.SaveToFile(FilePath: String);
146     var
147     ini : TMemIniFile;
148     i : Integer;
149     resWord : TResistWord;
150     begin
151     if FileExists(FilePath) then begin
152     try
153     DeleteFile(FilePath);
154     except
155     end;
156     end;
157     ini := TMemIniFile.Create(FilePath);
158     try
159     for i :=0 to FDictionary.Count - 1 do begin
160     resWord := TResistWord(FDictionary.Objects[i]);
161     ini.WriteString(resWord.FCategory, resWord.FKey, resWord.FText);
162     end;
163     ini.UpdateFile;
164     finally
165     ini.Free;
166     end;
167     end;
168     //! ツデツスツトツδ可クツタ
169     procedure TInputAssistDM.DataModuleDestroy(Sender: TObject);
170     var
171     i : Integer;
172     begin
173     if (FDictionary <> nil) then begin
174     for i := FDictionary.Count - 1 downto 0 do begin
175     TResistWord(FDictionary.Objects[i]).Free;
176     end;
177     FDictionary.Clear;
178     FDictionary.Capacity := 0;
179     FDictionary.Free;
180     end;
181     end;
182     //! ツコツδ督スツトツδ可クツタ
183     procedure TInputAssistDM.DataModuleCreate(Sender: TObject);
184     begin
185     FDictionary := TStringList.Create;
186     FDictionary.Duplicates := dupAccept;
187     FDictionary.Sorted := True;
188     end;
189     //! ツ登ツ録ツ単ツ呼卍青板柴?毒セ
190     function TInputAssistDM.ResistWordCount : Integer;
191     begin
192     Result := 0;
193     if (FDictionary <> nil) then begin
194     Result := FDictionary.Count;
195     end;
196     end;
197     //! ツ登ツ録ツ単ツ呼卍柴?毒セ
198     function TInputAssistDM.GetResistWord(Index: Integer): TResistWord;
199     begin
200     Result := nil;
201     if (FDictionary <> nil) then begin
202     if (Index >= 0) and (Index < FDictionary.Count) then begin
203     Result := TResistWord(FDictionary.Objects[index]);
204     end;
205     end;
206     end;
207     //! ツ登ツ録ツ単ツ呼卍て堋催ュツ渉?/span>
208     procedure TInputAssistDM.DeleteResistWord(ResistWord: TResistWord);
209     var
210     i : Integer;
211     begin
212     if (FDictionary <> nil) then begin
213     for i := 0 to FDictionary.Count - 1 do begin
214     if (ResistWord = FDictionary.Objects[i]) then begin
215     TResistWord(FDictionary.Objects[i]).Free;
216     FDictionary.Delete(i);
217     break;
218     end;
219     end;
220     end;
221     end;
222     //! ツ登ツ録ツ単ツ呼卍津?嘉?/span>
223     function TInputAssistDM.Add(Key: String): TResistWord;
224     var
225     resWord : TResistWord;
226     begin
227     Result := nil;
228     if (FDictionary <> nil) then begin
229     resWord := TResistWord.Create;
230     resWord.SetKey(Key);
231     resWord.SetCategory('ツカツテツゴツδ?#39;);
232     resWord.SetText('ツ墜債型ツ頁?#39;);
233     FDictionary.AddObject(Key, resWord);
234     Result := resWord;
235     end;
236     end;
237     //! ツ登ツ録ツ単ツ呼卍て堋キツーツ米篠更
238     procedure TInputAssistDM.ChangeKey(ResistWord: TResistWord);
239     var
240     i : Integer;
241     begin
242     if (FDictionary <> nil) then begin
243     for i := 0 to FDictionary.Count - 1 do begin
244     if (ResistWord = FDictionary.Objects[i]) then begin
245     FDictionary.Strings[i] := ResistWord.GetKey;
246     break;
247     end;
248     end;
249     end;
250     end;
251     //! Keyツて堕篠敖づつ登ツ録ツでつて卍づ?ね伉づゥツ単ツ呼卍て堕柴?毒セ
252     function TInputAssistDM.GetStartWithKeyResistWords(Key: String; var list: TStringList): Integer;
253     var
254     i : Integer;
255     resWord : TResistWord;
256    
257     begin
258     Result := 0;
259     if (FDictionary <> nil) and (list <> nil) then begin
260     Key := ZenToHan(Key);
261     for i := 0 to FDictionary.Count - 1 do begin
262     if (AnsiPos(Key, ZenToHan(FDictionary.Strings[i])) = 1) then begin
263     Inc(Result);
264     resWord := TResistWord(FDictionary.Objects[i]);
265     list.AddObject(resWord.GetKey + '(' +
266     resWord.GetCategory + ')', resWord);
267     end else if (Result > 0) then begin
268     //ツソツーツトツでつて卍づ?ね伉づゥツで?ツづァツ、ツヒツッツトツね?て卍づ篠連ツ惰?ね?づゥツづ債つク
269     break;
270     end;
271     end;
272     end;
273     end;
274     //! Keyツて堕カツテツゴツδ環づ可篠敖づつ登ツ録ツでつて卍づ?ね伉づゥツ単ツ呼卍て堕柴?毒セ
275     function TInputAssistDM.GetStartWithCategoryResistWords(Key: String; var list: TStringList): Integer;
276     var
277     i : Integer;
278     resWord : TResistWord;
279     begin
280     Result := 0;
281     if (FDictionary <> nil) and (list <> nil) then begin
282     Key := ZenToHan(Key);
283     for i := 0 to FDictionary.Count - 1 do begin
284     resWord := TResistWord(FDictionary.Objects[i]);
285     if (AnsiPos(Key, ZenToHan(resWord.GetCategory)) = 1) then begin
286     Inc(Result);
287     list.AddObject(resWord.GetKey + '(' +
288     resWord.GetCategory + ')', resWord);
289     end;
290     end;
291 h677 1.2 list.CustomSort(CategorySort);
292 h677 1.1 end;
293     end;
294 h677 1.2
295 h677 1.1 //! ツソツーツトツて堋湘ウツ妥板て堋柴?毒セ
296     function TInputAssistDM.GetSorted: Boolean;
297     begin
298     Result := False;
299     if (FDictionary <> nil) then begin
300     Result := FDictionary.Sorted;
301     end;
302     end;
303     //! ツソツーツトツ湘ウツ妥板て堋静敖墜?/span>
304     procedure TInputAssistDM.SetSorted(Value: Boolean);
305     begin
306     if (FDictionary <> nil) then begin
307     FDictionary.Sorted := Value;
308     end;
309     end;
310    
311 h677 1.2 //! Keyツて堕カツテツゴツδ環づ可篠敖づつ登ツ録ツ単ツ呼卍て堕陛板ね?篠楪て堋ソツーツトツ用ツ氾、ツ較ツδ?ソツッツド
312     function CategorySort(List: TStringList; Index1, Index2: Integer): Integer;
313     var
314     resWord1 : TResistWord;
315     resWord2 : TResistWord;
316     begin
317     Result := 0;
318     try
319     resWord1 := TResistWord(List.Objects[Index1]);
320     resWord2 := TResistWord(List.Objects[Index2]);
321     Result := AnsiCompareStr(resWord1.GetCategory, resWord2.GetCategory);
322     if (Result = 0) then begin
323     Result := AnsiCompareStr(resWord1.GetKey, resWord2.GetKey);
324     end;
325     except
326     end;
327     end;
328    
329 h677 1.1 end.

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