1 unit InputAssistDataModule;
6 SysUtils, Classes, Windows;
11 TInputAssistDM = class(TDataModule)
12 procedure DataModuleDestroy(Sender: TObject);
13 procedure DataModuleCreate(Sender: TObject);
17 FDictionary : TStringList; ///<
\93o
\98^
\92P
\8cê
\82Æ
\92è
\8c^
\95¶
\82Ì
\8e«
\8f\91
18 function GetSorted: Boolean; ///<
\83\
\81[
\83g
\82Ì
\8fó
\91Ô
\82Ì
\8eæ
\93¾
19 procedure SetSorted(Value: Boolean); ///<
\83\
\81[
\83g
\8fó
\91Ô
\82Ì
\90Ý
\92è
23 property Sorted : Boolean read GetSorted write SetSorted;
24 procedure Init(FilePath: String);
25 procedure SaveToFile(FilePath: String);
26 function ResistWordCount : Integer; ///<
\93o
\98^
\92P
\8cê
\90\94\8eæ
\93¾
27 function GetResistWord(Index: Integer): TResistWord; ///<
\93o
\98^
\92P
\8cê
\8eæ
\93¾
28 procedure DeleteResistWord(ResistWord: TResistWord); ///<
\93o
\98^
\92P
\8cê
\82Ì
\8dí
\8f\9c
29 function Add(Key: String): TResistWord; ///<
\93o
\98^
\92P
\8cê
\92Ç
\89Á
30 procedure ChangeKey(ResistWord: TResistWord); ///<
\93o
\98^
\92P
\8cê
\82Ì
\83L
\81[
\95Ï
\8dX
31 //! Key
\82ð
\83L
\81[
\82É
\8e\9d\82Â
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82é
\92P
\8cê
\82ð
\8eæ
\93¾
32 function GetStartWithKeyResistWords(Key: String; var list: TStringList): Integer;
33 //! Key
\82ð
\83J
\83e
\83S
\83\8a\82É
\8e\9d\82Â
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82é
\92P
\8cê
\82ð
\8eæ
\93¾
34 function GetStartWithCategoryResistWords(Key: String; var list: TStringList): Integer;
35 //! Key
\82Ì
\83J
\83e
\83S
\83\8a\82É
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82é
\92P
\8cê
\82ð
\8eæ
\93¾
36 function GetCategoryResistWords(Key: String; var list: TStringList): Integer;
37 //!
\93o
\98^
\8dÏ
\82Ý
\83L
\81[
\82Ì
\91S
\82Ä
\82Ì
\83J
\83e
\83S
\83\8a\83\8a\83X
\83g
\8eæ
\93¾
38 procedure GetCategoryList(var list: TStringList);
42 TResistWord = class(TObject)
44 FKey : String; ///<
\95Ï
\8a·
\8e\9e\82Ì
\83L
\81[
\82É
\82È
\82é
45 FCategory : String; ///<
\95ª
\97Þ
46 FText : String; ///<
\92è
\8c^
\95¶
48 function GetKey: String;
49 procedure SetKey(Value: String);
50 function GetCategory: String;
51 procedure SetCategory(Value: String);
52 function GetText: String;
53 procedure SetText(Value: String);
54 property Key: String read FKey write FKey;
55 property Category: String read FCategory write FCategory;
56 property Text: String read GetText write SetText;
59 function CategorySort(List: TStringList; Index1, Index2: Integer): Integer;
61 InputAssistDM: TInputAssistDM;
69 //! FKey
\82É
\90Ý
\92è
\82³
\82ê
\82Ä
\82¢
\82é
\92l
\82ð
\8eæ
\93¾
\82·
\82é
70 function TResistWord.GetKey: String;
72 //
\83G
\83X
\83P
\81[
\83v
\82µ
\82Ä
\82¢
\82é=
\82ð
\95\9c\8c³
\82·
\82é
73 Result := MojuUtils.CustomStringReplace(FKey, '=', '=');
75 //! FKey
\82É
\92l
\82ð
\90Ý
\92è
\82·
\82é
76 procedure TResistWord.SetKey(Value: String);
78 //=
\82Í
\95Û
\91¶
\8e\9e\82É
\8eg
\82¤
\82Ì
\82Å
\83G
\83X
\83P
\81[
\83v
\82·
\82é
79 FKey := MojuUtils.CustomStringReplace(Value, '=', '=');
81 //! FCategory
\82É
\90Ý
\92è
\82³
\82ê
\82Ä
\82¢
\82é
\92l
\82ð
\8eæ
\93¾
\82·
\82é
82 function TResistWord.GetCategory: String;
84 //
\83G
\83X
\83P
\81[
\83v
\82µ
\82Ä
\82¢
\82é=
\82ð
\95\9c\8c³
\82·
\82é
85 Result := MojuUtils.CustomStringReplace(FCategory, '=', '=');
87 //! FCategory
\82É
\92l
\82ð
\90Ý
\92è
\82·
\82é
88 procedure TResistWord.SetCategory(Value: String);
90 //=
\82Í
\95Û
\91¶
\8e\9e\82É
\8eg
\82¤
\82Ì
\82Å
\83G
\83X
\83P
\81[
\83v
\82·
\82é
91 FCategory := MojuUtils.CustomStringReplace(Value, '=', '=');
93 //! FText
\82É
\90Ý
\92è
\82³
\82ê
\82Ä
\82¢
\82é
\92l
\82ð
\8eæ
\93¾
\82·
\82é
94 function TResistWord.GetText: String;
96 //
\83G
\83X
\83P
\81[
\83v
\82µ
\82Ä
\82¢
\82é=
\82ð
\95\9c\8c³
\82·
\82é
97 Result := MojuUtils.CustomStringReplace(FText, '=', '=');
98 // #1
\82É
\82µ
\82½
\89ü
\8ds
\83R
\81[
\83h
\82ð#13#10
\82É
\95\9c\8c³
\82·
\82é
99 Result := MojuUtils.CustomStringReplace(Result, #1, #13#10);
101 procedure TResistWord.SetText(Value: String);
103 //=
\82Í
\95Û
\91¶
\8e\9e\82É
\8eg
\82¤
\82Ì
\82Å
\83G
\83X
\83P
\81[
\83v
\82·
\82é
104 FText := MojuUtils.CustomStringReplace(Value, '=', '=');
105 //
\89ü
\8ds
\83R
\81[
\83h
\82ð#1
\82É
\82·
\82é
\81i1
\8ds
\82É
\82·
\82é
\82½
\82ß)
106 FText := MojuUtils.CustomStringReplace(FText, #13#10, #1);
108 //!
\83t
\83@
\83C
\83\8b\82ð
\93Ç
\82Ý
\8d\9e\82ñ
\82Å
\8f\89\8aú
\89»
\82·
\82é
109 procedure TInputAssistDM.Init(FilePath: String);
112 sections: TStringList;
115 resWord : TResistWord;
119 // ini
\83t
\83@
\83C
\83\8b\82ª
\96³
\82¯
\82ê
\82Î
\81A
\83f
\83t
\83H
\83\8b\83g
\82ð
\83\8a\83l
\81[
\83\80\82·
\82é
120 if not FileExists(FilePath) then begin
122 PChar(ChangeFileExt(FilePath, '.default')),
123 PChar(FilePath), True);
126 //
\83t
\83@
\83C
\83\8b\82Ì
\91¶
\8dÝ
\82ð
\8am
\94F
127 if FileExists(FilePath) then begin
128 ini := TMemIniFile.Create(FilePath);
129 sections := TStringList.Create;
130 keys := TStringList.Create;
132 ini.ReadSections(sections);
134 for i :=0 to sections.Count - 1 do begin
136 ini.ReadSection(sections[i], keys);
137 for j := 0 to keys.Count - 1 do begin
138 resWord := TResistWord.Create;
139 resWord.SetCategory(sections[i]);
140 resWord.SetKey(keys[j]);
141 resWord.SetText(ini.ReadString(sections[i], keys[j], ''));
142 FDictionary.AddObject(resWord.GetKey, resWord);
156 //!
\8ew
\92è
\82³
\82ê
\82½
\83p
\83X
\82Ì
\83t
\83@
\83C
\83\8b\82É
\95Û
\91¶
\82·
\82é
157 procedure TInputAssistDM.SaveToFile(FilePath: String);
161 resWord : TResistWord;
163 if FileExists(FilePath) then begin
165 SysUtils.DeleteFile(FilePath);
169 ini := TMemIniFile.Create(FilePath);
171 for i :=0 to FDictionary.Count - 1 do begin
172 resWord := TResistWord(FDictionary.Objects[i]);
173 ini.WriteString(resWord.FCategory, resWord.FKey, resWord.FText);
180 //!
\83f
\83X
\83g
\83\89\83N
\83^
181 procedure TInputAssistDM.DataModuleDestroy(Sender: TObject);
185 if (FDictionary <> nil) then begin
186 for i := FDictionary.Count - 1 downto 0 do begin
187 TResistWord(FDictionary.Objects[i]).Free;
190 FDictionary.Capacity := 0;
194 //!
\83R
\83\93\83X
\83g
\83\89\83N
\83^
195 procedure TInputAssistDM.DataModuleCreate(Sender: TObject);
197 FDictionary := TStringList.Create;
198 FDictionary.Duplicates := dupAccept;
199 FDictionary.Sorted := True;
201 //!
\93o
\98^
\92P
\8cê
\90\94\8eæ
\93¾
202 function TInputAssistDM.ResistWordCount : Integer;
205 if (FDictionary <> nil) then begin
206 Result := FDictionary.Count;
209 //!
\93o
\98^
\92P
\8cê
\8eæ
\93¾
210 function TInputAssistDM.GetResistWord(Index: Integer): TResistWord;
213 if (FDictionary <> nil) then begin
214 if (Index >= 0) and (Index < FDictionary.Count) then begin
215 Result := TResistWord(FDictionary.Objects[index]);
219 //!
\93o
\98^
\92P
\8cê
\82Ì
\8dí
\8f\9c
220 procedure TInputAssistDM.DeleteResistWord(ResistWord: TResistWord);
224 if (FDictionary <> nil) then begin
225 for i := 0 to FDictionary.Count - 1 do begin
226 if (ResistWord = FDictionary.Objects[i]) then begin
227 TResistWord(FDictionary.Objects[i]).Free;
228 FDictionary.Delete(i);
234 //!
\93o
\98^
\92P
\8cê
\92Ç
\89Á
235 function TInputAssistDM.Add(Key: String): TResistWord;
237 resWord : TResistWord;
240 if (FDictionary <> nil) then begin
241 resWord := TResistWord.Create;
243 resWord.SetCategory('
\83J
\83e
\83S
\83\8a');
244 resWord.SetText('
\92è
\8c^
\95¶');
245 FDictionary.AddObject(Key, resWord);
249 //!
\93o
\98^
\92P
\8cê
\82Ì
\83L
\81[
\95Ï
\8dX
250 procedure TInputAssistDM.ChangeKey(ResistWord: TResistWord);
254 if (FDictionary <> nil) then begin
255 for i := 0 to FDictionary.Count - 1 do begin
256 if (ResistWord = FDictionary.Objects[i]) then begin
257 FDictionary.Strings[i] := ResistWord.GetKey;
263 //! Key
\82ð
\8e\9d\82Â
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82é
\92P
\8cê
\82ð
\8eæ
\93¾
264 function TInputAssistDM.GetStartWithKeyResistWords(Key: String; var list: TStringList): Integer;
267 resWord : TResistWord;
271 if (FDictionary <> nil) and (list <> nil) then begin
272 Key := ZenToHan(Key);
273 for i := 0 to FDictionary.Count - 1 do begin
274 if (AnsiPos(Key, ZenToHan(FDictionary.Strings[i])) = 1) then begin
276 resWord := TResistWord(FDictionary.Objects[i]);
277 list.AddObject(resWord.GetKey + '(' +
278 resWord.GetCategory + ')', resWord);
279 end else if (Result > 0) then begin
280 //
\83\
\81[
\83g
\82³
\82ê
\82Ä
\82¢
\82é
\82©
\82ç
\81A
\83q
\83b
\83g
\82·
\82ê
\82Î
\98A
\91±
\82·
\82é
\82Í
\82¸
286 //! Key
\82ð
\83J
\83e
\83S
\83\8a\82É
\8e\9d\82Â
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82é
\92P
\8cê
\82ð
\8eæ
\93¾
287 function TInputAssistDM.GetStartWithCategoryResistWords(Key: String; var list: TStringList): Integer;
290 resWord : TResistWord;
293 if (FDictionary <> nil) and (list <> nil) then begin
294 Key := ZenToHan(Key);
295 for i := 0 to FDictionary.Count - 1 do begin
296 resWord := TResistWord(FDictionary.Objects[i]);
297 if (AnsiPos(Key, ZenToHan(resWord.GetCategory)) = 1) then begin
299 list.AddObject(resWord.GetKey + '(' +
300 resWord.GetCategory + ')', resWord);
303 list.CustomSort(CategorySort);
307 //!
\83\
\81[
\83g
\82Ì
\8fó
\91Ô
\82Ì
\8eæ
\93¾
308 function TInputAssistDM.GetSorted: Boolean;
311 if (FDictionary <> nil) then begin
312 Result := FDictionary.Sorted;
315 //!
\83\
\81[
\83g
\8fó
\91Ô
\82Ì
\90Ý
\92è
316 procedure TInputAssistDM.SetSorted(Value: Boolean);
318 if (FDictionary <> nil) then begin
319 FDictionary.Sorted := Value;
322 //! Key
\82Ì
\83J
\83e
\83S
\83\8a\82É
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82é
\92P
\8cê
\82ð
\8eæ
\93¾
323 function TInputAssistDM.GetCategoryResistWords(Key: String; var list: TStringList): Integer;
326 resWord : TResistWord;
329 if (FDictionary <> nil) and (list <> nil) then begin
330 for i := 0 to FDictionary.Count - 1 do begin
331 resWord := TResistWord(FDictionary.Objects[i]);
332 if (Key = resWord.GetCategory) then begin
334 list.AddObject(resWord.GetKey + '(' +
335 resWord.GetCategory + ')', resWord);
338 list.CustomSort(CategorySort);
342 //!
\93o
\98^
\8dÏ
\82Ý
\83L
\81[
\82Ì
\91S
\82Ä
\82Ì
\83J
\83e
\83S
\83\8a\83\8a\83X
\83g
\8eæ
\93¾
343 procedure TInputAssistDM.GetCategoryList(var list: TStringList);
347 if (FDictionary <> nil) and (list <> nil) then begin
348 //
\8fd
\95¡
\83`
\83F
\83b
\83N
\82ðTStringList
\82Ì
\8b@
\94\
\82Å
\8ds
\82¤
350 list.Duplicates := dupIgnore;
353 for i := 0 to FDictionary.Count - 1 do begin
354 list.Add(TResistWord(FDictionary.Objects[i]).GetCategory);
360 //! Key
\82ð
\83J
\83e
\83S
\83\8a\82É
\8e\9d\82Â
\93o
\98^
\92P
\8cê
\82ð
\95Ô
\82·
\8e\9e\82Ì
\83\
\81[
\83g
\97p
\94ä
\8ar
\83\81\83\
\83b
\83h
361 function CategorySort(List: TStringList; Index1, Index2: Integer): Integer;
363 resWord1 : TResistWord;
364 resWord2 : TResistWord;
368 resWord1 := TResistWord(List.Objects[Index1]);
369 resWord2 := TResistWord(List.Objects[Index2]);
370 Result := AnsiCompareStr(resWord1.GetCategory, resWord2.GetCategory);
371 if (Result = 0) then begin
372 Result := AnsiCompareStr(resWord1.GetKey, resWord2.GetKey);