Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/InputAssistDataModule.pas

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


Revision 1.1 - (show annotations) (download) (as text)
Sat Jan 14 07:44:14 2006 UTC (18 years, 3 months ago) by h677
Branch: MAIN
File MIME type: text/x-pascal
入力アシスト(定型文入力のようなもの)を組み込んでみた。

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; ///< ?o?^?P???????^?????鼎??
18 function GetSorted: Boolean; ///< ?\?[?g???坦???????転
19 procedure SetSorted(Value: Boolean); ///< ?\?[?g?坦????????
20 public
21 { Public ?辿?転 }
22 property Sorted : Boolean read GetSorted write SetSorted;
23 procedure Init(FilePath: String);
24 procedure SaveToFile(FilePath: String);
25 function ResistWordCount : Integer; ///<?o?^?P???????転
26 function GetResistWord(Index: Integer): TResistWord; ///< ?o?^?P?????転
27 procedure DeleteResistWord(ResistWord: TResistWord); ///< ?o?^?P?????鱈??
28 function Add(Key: String): TResistWord; ///< ?o?^?P??????
29 procedure ChangeKey(ResistWord: TResistWord); ///< ?o?^?P?????L?[???X
30 //! Key???L?[???????o?^?????????辿?P???????転
31 function GetStartWithKeyResistWords(Key: String; var list: TStringList): Integer;
32 //! Key???J?e?S?????????o?^?????????辿?P???????転
33 function GetStartWithCategoryResistWords(Key: String; var list: TStringList): Integer;
34 end;
35
36 TResistWord = class(TObject)
37 private
38 FKey : String; ///< ?????????L?[?????辿
39 FCategory : String; ///< ???鄭
40 FText : String; ///< ???^??
41 public
42 function GetKey: String;
43 procedure SetKey(Value: String);
44 function GetCategory: String;
45 procedure SetCategory(Value: String);
46 function GetText: String;
47 procedure SetText(Value: String);
48 property Key: String read FKey write FKey;
49 property Category: String read FCategory write FCategory;
50 property Text: String read GetText write SetText;
51 end;
52 var
53 InputAssistDM: TInputAssistDM;
54
55 implementation
56
57 uses
58 MojuUtils, IniFiles;
59
60 {$R *.dfm}
61 //! FKey???????????????辿?l?????転???辿
62 function TResistWord.GetKey: String;
63 begin
64 //?G?X?P?[?v?直?????辿=?????????辿
65 Result := MojuUtils.CustomStringReplace(FKey, '&#61;', '=');
66 end;
67 //! FKey???l?????????辿
68 procedure TResistWord.SetKey(Value: String);
69 begin
70 //=???徹???????g?造???長?G?X?P?[?v???辿
71 FKey := MojuUtils.CustomStringReplace(Value, '=', '&#61;');
72 end;
73 //! FCategory???????????????辿?l?????転???辿
74 function TResistWord.GetCategory: String;
75 begin
76 //?G?X?P?[?v?直?????辿=?????????辿
77 Result := MojuUtils.CustomStringReplace(FCategory, '&#61;', '=');
78 end;
79 //! FCategory???l?????????辿
80 procedure TResistWord.SetCategory(Value: String);
81 begin
82 //=???徹???????g?造???長?G?X?P?[?v???辿
83 FCategory := MojuUtils.CustomStringReplace(Value, '=', '&#61;');
84 end;
85 //! FText???????????????辿?l?????転???辿
86 function TResistWord.GetText: String;
87 begin
88 //?G?X?P?[?v?直?????辿=?????????辿
89 Result := MojuUtils.CustomStringReplace(FText, '&#61;', '=');
90 // #1???直???端?s?R?[?h??#13#10?????????辿
91 Result := MojuUtils.CustomStringReplace(Result, #1, #13#10);
92 end;
93 procedure TResistWord.SetText(Value: String);
94 begin
95 //=???徹???????g?造???長?G?X?P?[?v???辿
96 FText := MojuUtils.CustomStringReplace(Value, '=', '&#61;');
97 //?端?s?R?[?h??#1?????辿?i1?s?????辿????)
98 FText := MojuUtils.CustomStringReplace(FText, #13#10, #1);
99 end;
100 //! ?t?@?C?????????????長???炭?泥???辿
101 procedure TInputAssistDM.Init(FilePath: String);
102 var
103 ini : TMemIniFile;
104 sections: TStringList;
105 keys: TStringList;
106 i, j : Integer;
107 resWord : TResistWord;
108 begin
109 FInit := True;
110 try
111 // ?t?@?C???????????m?F
112 if FileExists(FilePath) then begin
113 ini := TMemIniFile.Create(FilePath);
114 sections := TStringList.Create;
115 keys := TStringList.Create;
116 try
117 ini.ReadSections(sections);
118
119 for i :=0 to sections.Count - 1 do begin
120 keys.Clear;
121 ini.ReadSection(sections[i], keys);
122 for j := 0 to keys.Count - 1 do begin
123 resWord := TResistWord.Create;
124 resWord.SetCategory(sections[i]);
125 resWord.SetKey(keys[j]);
126 resWord.SetText(ini.ReadString(sections[i], keys[j], ''));
127 FDictionary.AddObject(resWord.GetKey, resWord);
128 end;
129 end;
130 finally
131 keys.Free;
132 sections.Free;
133 ini.Free;
134 end;
135 end;
136
137 except
138 FInit := False;
139 end;
140 end;
141 //! ?w?????????p?X???t?@?C?????徹?????辿
142 procedure TInputAssistDM.SaveToFile(FilePath: String);
143 var
144 ini : TMemIniFile;
145 i : Integer;
146 resWord : TResistWord;
147 begin
148 if FileExists(FilePath) then begin
149 try
150 DeleteFile(FilePath);
151 except
152 end;
153 end;
154 ini := TMemIniFile.Create(FilePath);
155 try
156 for i :=0 to FDictionary.Count - 1 do begin
157 resWord := TResistWord(FDictionary.Objects[i]);
158 ini.WriteString(resWord.FCategory, resWord.FKey, resWord.FText);
159 end;
160 ini.UpdateFile;
161 finally
162 ini.Free;
163 end;
164 end;
165 //! ?f?X?g???N?^
166 procedure TInputAssistDM.DataModuleDestroy(Sender: TObject);
167 var
168 i : Integer;
169 begin
170 if (FDictionary <> nil) then begin
171 for i := FDictionary.Count - 1 downto 0 do begin
172 TResistWord(FDictionary.Objects[i]).Free;
173 end;
174 FDictionary.Clear;
175 FDictionary.Capacity := 0;
176 FDictionary.Free;
177 end;
178 end;
179 //! ?R???X?g???N?^
180 procedure TInputAssistDM.DataModuleCreate(Sender: TObject);
181 begin
182 FDictionary := TStringList.Create;
183 FDictionary.Duplicates := dupAccept;
184 FDictionary.Sorted := True;
185 end;
186 //! ?o?^?P???????転
187 function TInputAssistDM.ResistWordCount : Integer;
188 begin
189 Result := 0;
190 if (FDictionary <> nil) then begin
191 Result := FDictionary.Count;
192 end;
193 end;
194 //! ?o?^?P?????転
195 function TInputAssistDM.GetResistWord(Index: Integer): TResistWord;
196 begin
197 Result := nil;
198 if (FDictionary <> nil) then begin
199 if (Index >= 0) and (Index < FDictionary.Count) then begin
200 Result := TResistWord(FDictionary.Objects[index]);
201 end;
202 end;
203 end;
204 //! ?o?^?P?????鱈??
205 procedure TInputAssistDM.DeleteResistWord(ResistWord: TResistWord);
206 var
207 i : Integer;
208 begin
209 if (FDictionary <> nil) then begin
210 for i := 0 to FDictionary.Count - 1 do begin
211 if (ResistWord = FDictionary.Objects[i]) then begin
212 TResistWord(FDictionary.Objects[i]).Free;
213 FDictionary.Delete(i);
214 break;
215 end;
216 end;
217 end;
218 end;
219 //! ?o?^?P??????
220 function TInputAssistDM.Add(Key: String): TResistWord;
221 var
222 resWord : TResistWord;
223 begin
224 Result := nil;
225 if (FDictionary <> nil) then begin
226 resWord := TResistWord.Create;
227 resWord.SetKey(Key);
228 resWord.SetCategory('?J?e?S??');
229 resWord.SetText('???^??');
230 FDictionary.AddObject(Key, resWord);
231 Result := resWord;
232 end;
233 end;
234 //! ?o?^?P?????L?[???X
235 procedure TInputAssistDM.ChangeKey(ResistWord: TResistWord);
236 var
237 i : Integer;
238 begin
239 if (FDictionary <> nil) then begin
240 for i := 0 to FDictionary.Count - 1 do begin
241 if (ResistWord = FDictionary.Objects[i]) then begin
242 FDictionary.Strings[i] := ResistWord.GetKey;
243 break;
244 end;
245 end;
246 end;
247 end;
248 //! Key???????o?^?????????辿?P???????転
249 function TInputAssistDM.GetStartWithKeyResistWords(Key: String; var list: TStringList): Integer;
250 var
251 i : Integer;
252 resWord : TResistWord;
253
254 begin
255 Result := 0;
256 if (FDictionary <> nil) and (list <> nil) then begin
257 Key := ZenToHan(Key);
258 for i := 0 to FDictionary.Count - 1 do begin
259 if (AnsiPos(Key, ZenToHan(FDictionary.Strings[i])) = 1) then begin
260 Inc(Result);
261 resWord := TResistWord(FDictionary.Objects[i]);
262 list.AddObject(resWord.GetKey + '(' +
263 resWord.GetCategory + ')', resWord);
264 end else if (Result > 0) then begin
265 //?\?[?g?????????辿???巽?A?q?b?g???????A?????辿???存
266 break;
267 end;
268 end;
269 end;
270 end;
271 //! Key???J?e?S?????????o?^?????????辿?P???????転
272 function TInputAssistDM.GetStartWithCategoryResistWords(Key: String; var list: TStringList): Integer;
273 var
274 i : Integer;
275 resWord : TResistWord;
276 begin
277 Result := 0;
278 if (FDictionary <> nil) and (list <> nil) then begin
279 Key := ZenToHan(Key);
280 for i := 0 to FDictionary.Count - 1 do begin
281 resWord := TResistWord(FDictionary.Objects[i]);
282 if (AnsiPos(Key, ZenToHan(resWord.GetCategory)) = 1) then begin
283 Inc(Result);
284 list.AddObject(resWord.GetKey + '(' +
285 resWord.GetCategory + ')', resWord);
286 end;
287 end;
288 end;
289 end;
290 //! ?\?[?g???坦???????転
291 function TInputAssistDM.GetSorted: Boolean;
292 begin
293 Result := False;
294 if (FDictionary <> nil) then begin
295 Result := FDictionary.Sorted;
296 end;
297 end;
298 //! ?\?[?g?坦????????
299 procedure TInputAssistDM.SetSorted(Value: Boolean);
300 begin
301 if (FDictionary <> nil) then begin
302 FDictionary.Sorted := Value;
303 end;
304 end;
305
306 end.

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