OSDN Git Service

NGワードでの透明あぼ〜んの実装
[gikonavigoeson/gikonavi.git] / AbonUnit.pas
1 unit AbonUnit;
2
3 interface
4 uses
5     Windows,Messages, ShellAPI, SysUtils, Classes,StdCtrls,StrUtils;
6
7 type
8   TIndiviAbon = record
9         Res: Integer;
10     option: Integer; // 0:\93§\96¾ 1:\92Ê\8fí\82 \82Ú\81[\82ñ
11   end;
12
13   TAbon = class(TObject)
14   private
15     { Private \90é\8c¾ }
16     Froot : String;
17     Flistpath : String;
18     FNGwordpath : String;
19     Ftokens : array of array of string;
20     FAbonRes : array of TIndiviAbon;
21     FAbonString : String;
22     FCutoffNum : Integer; //\82±\82Ì\90\94\88È\8fã\98A\91±\82·\82é\93¯\82\89p\8e\9a\82ðNG\83\8f\81[\83h\82Æ\82·\82é
23     FDeleterlo : Boolean; //&rlo;\82ð\8dí\82é\82© //\92Ç\89Á&lro;\82à\8dí\82é
24     FReplaceul :Boolean ; //<ul>\83^\83O\82ð<br>\83^\83O\82É\92u\8a·\82·\82é\82©
25     FReverse : Boolean ;  //NG\83\8f\81[\83h\82Å\82Ì\82 \82Ú\81`\82ñ\82Ì\8c\8b\89Ê\82ð\94½\93]\82³\82¹\82é\82©
26     FAbonPopupRes : Boolean; //\83\8c\83X\83|\83b\83v\83A\83b\83v\82Ì\8e\9e\82É\82 \82Ú\81[\82ñ\82·\82é\82©
27     FCreateNGwordFile : Boolean; //\8ew\92è\82³\82ê\82½path\82ÉNG\83\8f\81[\83htxt\82ª\96³\82©\82Á\82½\82Æ\82«\82É\8e©\93®\93I\82É\90\90¬\82·\82é\82©
28     FNGwordFileIndex : Integer; //\8c»\8dÝ\93Ç\82Ý\8d\9e\82ñ\82Å\82éNG\83\8f\81[\83h\82ªlist\82Ì\89½\8ds\96Ú\82©
29     FNGwordname : String; //\8c»\8dÝ\93Ç\82Ý\8d\9e\82ñ\82Å\82éNG\83\8f\81[\83h\82Ì\95\\8e¦\96¼
30     FIndividualFileName : String;       //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82Ì\83t\83@\83C\83\8b\96¼
31     FReturnNGwordLineNum : Boolean;     //NG\83\8f\81[\83h\82Ì\8ds\90\94\82ð\95Ô\82·\81B
32     FSetNGResAnchor : Boolean; //NG\82É\8aY\93\96\82µ\82½\82Æ\82«\82É\96{\95\82É\82»\82Ì\83\8c\83X\82Ö\82Ì\83\8c\83X\83A\83\93\83J\81[\82ð\82Â\82¯\82é\82©\82Ç\82¤\82©
33     procedure SetTokens(index: integer ; argline:String);
34     function Getlistpath() : String;
35     procedure Setlistpath(const Value : String);
36     function LoadListFile(path :String;listStringList : TStringList) : Boolean;
37     function ReadNGwordslist(line : Integer) : Boolean;
38     function LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
39   public
40     { Public \90é\8c¾ }
41     constructor Create; // \83R\83\93\83X\83g\83\89\83N\83^
42     destructor Destroy; override; // \83f\83X\83g\83\89\83N\83^
43     property Deleterlo: Boolean read FDeleterlo write FDeleterlo  default false;
44     property Replaceul: Boolean read FReplaceul write FReplaceul  default false;
45     property Reverse: Boolean read FReverse write FReverse  default false;
46     property CreateNGwordFile: Boolean read FCreateNGwordFile write FCreateNGwordFile;
47     property AbonString : String read FAbonString write FAbonString;
48     property  AbonPopupRes : Boolean read FAbonPopupRes write FAbonPopupRes default false;
49     property listpath : String read Getlistpath write Setlistpath;
50     property NGwordFileIndex : Integer read FNGwordFileIndex write FNGwordFileIndex default 0;
51     property NGwordname : String read FNGwordname write FNGwordname;
52         property ReturnNGwordLineNum : Boolean read FReturnNGwordLineNum write FReturnNGwordLineNum default false;
53     property SetNGResAnchor : Boolean read FSetNGResAnchor write FSetNGResAnchor default false;
54     procedure Setroot(root :String);
55     function Getroot() : String;
56
57     function Getfullpath(argpath : String) : String;
58     procedure SetNGwordpath(path :String);
59     function GetNGwordpath() : String;
60     function LoadFromNGwordFile(path :String) : Boolean;
61     function ReLoadFromNGwordFile() : Boolean;
62     procedure LoadFromStringList( bufstl : TStringList );
63     function CheckAbonPopupRes(line : String) :Boolean;
64     function FindNGwords(line : String) : Boolean; overload;//1\83\89\83C\83\93\82¸\82Â\97p\81B
65     function FindNGwords(line : String; var NGwordsLineNum : Integer) : Boolean; overload;//1\83\89\83C\83\93\82¸\82Â\97p\81B
66     function FindNGwords(line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean; overload;//1\83\89\83C\83\93\82¸\82Â\97p\81B
67     function Cutoff(line : String) : Boolean; //CutOff\92l\88È\8fã\8cÂ\82Ì\93¯\82\89p\90\94\82ª\95À\82ñ\82Å\82¢\82½\82çtrue
68     //\82 \82Ú\81`\82ñ\8f\88\97\9d(NG\83\8f\81[\83h\82Å\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O)
69     procedure Execute(var ThreadStrings : TStringList); overload;
70     procedure Execute(var ThreadStrings : TStringList; NGwords : TStringList); overload;
71     procedure Execute(var ThreadStrings : TStringList; NGwords : TStrings); overload;
72     //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82µ\82å\82è
73     procedure IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String);
74     procedure AddIndividualAbon( ResNum : Integer ; option : Integer);
75     procedure DeleteIndividualAbon( ResNum : Integer);
76     function GetAbonResCount() : Integer;
77     function GetAbonResString(Num : Integer) : String;
78     function CheckIndividualAbonList(ResNum : Integer) : Boolean;
79     //--
80     function ExecuteFile(datfilepath : String; NGwordpath : String) : Boolean; overload;//DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
81     function ExecuteFile(datfilepath : String; resnum : Integer) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
82     function ExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
83     function ReverseExecuteFile(datfilepath : String) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
84     function ReverseExecuteFile(datfilepath : String; resnum : Integer) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
85     function ReverseExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
86     //--
87     procedure EditNGwords();  //NGword.txt\82ð\8aJ\82­\81B
88     function ShowAllTokens() : String;  //\83f\83o\83b\83O\97p
89     //--
90     procedure GoHome();//List\82Ì\82P\8ds\96Ú\82ð\93Ç\82Þ
91     function GoForward() : Boolean; //List\82Ì\88ê\82Â\8e\9f\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
92     function GoBack() : Boolean; //List\82Ì\88ê\82Â\91O\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
93   end;
94 var
95     Abon1 :TAbon;
96 const
97     NGwordListFileName : String = 'NGwords.list';
98
99 implementation
100
101 constructor TAbon.Create;
102 begin
103     // \8f\89\8aú\89»
104     FAbonString := '&nbsp;<>&nbsp;<>&nbsp;<>&nbsp;&nbsp;<><>';
105     FCreateNGwordFile := true;
106     SetLength(FAbonRes,1);
107     FAbonRes[0].Res := 0;
108     FAbonRes[0].option := -1;
109
110 end;
111
112 destructor TAbon.Destroy;
113 begin
114     inherited;
115 end;
116 //root\82ÍExe\config\NGwords\83t\83H\83\8b\83_
117 procedure TAbon.Setroot(root :String);
118 var
119     bufStringList : TStringList;
120 begin
121     bufStringList := TStringList.Create;
122     try
123         if not DirectoryExists(root) then begin
124             CreateDir(root);
125         end;
126         if root[Length(root)] <> '\' then begin
127             root := root + '\';
128         end;
129         Flistpath := root + NGwordListFileName;
130         LoadListFile(Flistpath, bufStringList);
131     finally
132         bufStringList.Free;
133     end;
134     Froot := root;
135 end;
136 function TAbon.Getroot() : String;
137 begin
138     Result := Froot;
139 end;
140 //NGwordpath\82ÍNGword.txt\82Ì\83t\83\8b\83p\83X
141 procedure TAbon.SetNGwordpath(path :String);
142 begin
143     FNGwordpath := Getfullpath(path);
144     LoadFromNGwordFile(FNGwordpath);
145 end;
146 function TAbon.GetNGwordpath() : String;
147 begin
148     Result :=  FNGwordpath;
149 end;
150 //\83t\83\8b\83p\83X\82Å\82È\82¯\82ê\82Î\83t\83\8b\83p\83X\82É\82µ\82Ä\95Ô\82·\81B
151 function TAbon.Getfullpath(argpath : String) : String;
152 begin
153     if AnsiPos(':\',argpath) <> 2 then begin  //\83h\83\89\83C\83u\82©\82ç\82Ì\83t\83\8b\83p\83X\82ª\96³\82¯\82ê\82Î
154         if Getroot() = '' then begin
155             Result := '';    //root\83p\83X\82ª\90Ý\92è\82³\82ê\82Ä\82È\82¢\82©\8bó\82É\82·\82é
156         end else begin
157             if (Froot[Length(Froot)] = '\') and (argpath[1] = '\') then begin  //\90æ\93ª\82Ì\\82ð\8dí\8f\9c
158                 Delete(argpath,1,1);
159             end;
160             Insert( Getroot(), argpath , 1);//root\83p\83X\82ð\91}\93ü
161             Result := argpath;
162         end;
163     end else begin
164         Result := argpath;
165     end;
166
167 end;
168 //NGword\83t\83@\83C\83\8b\82Ì\93Ç\82Ý\8d\9e\82Ý
169 function TAbon.LoadFromNGwordFile(path :String) : boolean;
170 var
171     bufstl : TStringList;
172 begin
173     path := Getfullpath(path);
174     if path = '' then begin
175         Result := false;
176     end else begin
177         bufstl := TStringList.Create;
178         try
179             try
180                 bufstl.LoadFromFile(path);
181                 LoadFromStringList( bufstl );
182                 Result := true;
183             except
184                 if CreateNGwordFile = true then begin
185                     bufstl.SaveToFile(path);
186                 end;
187                 Result := false;
188             end;
189         finally
190             bufstl.Free;
191         end;
192     end;
193
194 end;
195 //NGword\83\8a\83X\83g\93Ç\82Ý\8d\9e\82Ý
196 procedure TAbon.LoadFromStringList( bufstl : TStringList );
197 var
198     i : integer;
199 begin
200     try
201         for i := bufstl.Count -1  downto 0 do begin
202             if bufstl.Strings[i] = '' then begin
203                 bufstl.Delete(i);
204             end;
205         end;
206         SetLength(Ftokens,bufstl.Count);
207         for i := 0  to bufstl.Count -1 do begin
208             SetTokens(i , bufstl.Strings[i]);
209         end;
210
211     except
212         Exit;
213     end;
214 end;
215 //NGwordpath\82ª\8aù\82É\90Ý\92è\82³\82ê\82Ä\82¢\82é\82Æ\82«\82Ì\83\8a\83\8d\81[\83h\97p\8aÖ\90\94
216 function TAbon.ReLoadFromNGwordFile() : boolean;
217 begin
218     if GetNGwordpath() ='' then begin
219         Result := false;
220     end else begin
221         Result := LoadFromNGwordFile( GetNGwordpath() );
222     end;
223 end;
224 function TAbon.Getlistpath() : String;
225 begin
226     Result := Flistpath;
227 end;
228 procedure TAbon.Setlistpath(const Value : String);
229 begin
230     Flistpath := Getfullpath(Value);
231 end;
232 //\88ê\8ds\82Ì\92\86\82Ì\83g\81[\83N\83\93\82ð\90Ø\82è\95ª\82¯\82Ä\83Z\83b\83g
233 procedure TAbon.SetTokens(index: integer ; argline : String);
234 var
235     ret : Integer;
236     bufstl : TStringList;
237     i : Integer;
238     pos : Integer;
239     buftoken : String;
240 begin
241     pos := 0;
242     bufstl := TStringList.Create;
243     try
244         if Length(argline) > 0 then begin
245                 pos := AnsiPos(#9,argline);
246             while pos <> 0 DO begin
247                 buftoken := Copy(argline,1,pos-1);
248                 Delete(argline,1,pos);
249                 if Length(buftoken) > 0 then begin
250                                 bufstl.Append(buftoken);
251                 end else if ( bufstl.Count = 0 ) then begin
252                     bufstl.Append('');
253                 end;
254                     pos := AnsiPos(#9,argline);
255             end;
256                 if Length(argline) > 0 then begin
257                         bufstl.Append(argline);
258             end;
259                 ret := bufstl.Count;
260                 SetLength(Ftokens[index],ret);
261                 for i := 0 to bufstl.Count - 1  do begin
262                         Ftokens[index][i] := bufstl.Strings[i];
263                 end;
264         end;
265     finally
266         bufstl.Free;
267     end;
268
269 end;
270 //Debug\97p\82¿\82á\82ñ\82ÆNG\83\8f\81[\83h\82ð\8fE\82¦\82Ä\82¢\82é\82©
271 function TAbon.ShowAllTokens() : String;
272 var
273     i : Integer;
274     j : Integer;
275     ret : String;
276 begin
277     for i := 0 to High(Ftokens) do begin
278         for j := 0 to High(Ftokens[i]) do begin
279             ret := ret + Ftokens[i][j];
280         end;
281     end;
282     Result := ret;
283
284
285
286 end;
287
288 //****************************************************************************//
289 //NG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82½\82çtrue\82ð\95Ô\82·\81B
290 function TAbon.FindNGwords(line : String) : Boolean;
291 var
292     lines : Integer;
293     cells : Integer;
294     hit : Boolean;
295     bufline : String;
296 begin
297     hit := false;
298     if AnsiPos(FAbonString,line) <> 1 then begin
299         for lines := 0 to High(Ftokens) do begin
300                 hit := true;
301             bufline := line;
302             for cells := 0 to High(Ftokens[lines]) do begin
303                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
304                         hit := false;
305                     break;
306                 end else begin
307                         Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
308                 end;
309             end;
310             if hit = true then begin
311                 break;
312             end;
313         end;
314     end;
315     Result := hit;
316 end;
317 //NG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82çtrue\82ð\95Ô\82µ\81A\82»\82ÌNG\83\8f\81[\83h\82Ì\8ds\90\94\82ðNGwordsLineNum\82É\93ü\82ê\82Ä\95Ô\82·
318 function TAbon.FindNGwords(line : String; var NGwordsLineNum : Integer) : Boolean;
319 var
320     lines : Integer;
321     cells : Integer;
322     hit : Boolean;
323     bufline : String;
324 begin
325     hit := false;
326     if AnsiPos(FAbonString,line) <> 1 then begin
327         for lines := 0 to High(Ftokens) do begin
328                 hit := true;
329             bufline := line;
330             for cells := 0 to High(Ftokens[lines]) do begin
331                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
332                         hit := false;
333                     break;
334                 end else begin
335                         Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
336                 end;
337             end;
338             if hit = true then begin
339                 NGwordsLineNum := lines + 1;
340                 break;
341             end;
342         end;
343     end;
344     Result := hit;
345 end;
346 //NG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82çtrue\82ð\95Ô\82µ\81A\82»\82ÌNG\83\8f\81[\83h\82Ì\8ds\90\94\82ðNGwordsLineNum\82É\93ü\82ê\82Ä\95Ô\82·\81B
347 //\82à\82µ\82à\93§\96¾\82 \82Ú\81`\82ñ\82É\82·\82é\82È\82çInbisible\82ðtrue\82É\82µ\82Ä\95Ô\82·
348 function TAbon.FindNGwords(line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean; //1\83\89\83C\83\93\82¸\82Â\97p\81B
349 var
350     lines : Integer;
351     cells : Integer;
352     hit : Boolean;
353     bufline : String;
354     start : Integer;
355 begin
356     hit := false;
357     if AnsiPos(FAbonString,line) <> 1 then begin
358         for lines := 0 to High(Ftokens) do begin
359                 hit := true;
360             bufline := line;
361             if Ftokens[lines][0] <> ''  then begin
362                 Invisible := false;
363                 start := 0;
364             end else begin
365                 Invisible := true;
366                 start := 1;
367             end;
368
369             for cells := start to High(Ftokens[lines]) do begin
370                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
371                     hit := false;
372                     break;
373                 end else begin
374                     Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
375                 end;
376             end;
377             if hit = true then begin
378                 NGwordsLineNum := lines + 1;
379                 break;
380             end;
381         end;
382     end;
383     Result := hit;
384 end;
385
386 //CutOff\92l\88È\8fã\8cÂ\82Ì\93¯\82\89p\90\94\82ª\95À\82ñ\82Å\82¢\82½\82çtrue
387 function TAbon.Cutoff(line : String) : Boolean;
388 var
389     i : Integer;
390     sheed : AnsiChar;
391     buf : String;
392     ret : Bool;
393 begin
394     ret := false;
395     if FCutoffNum <> 0 then begin
396         for i := 65 to 90 do begin
397             sheed := Chr(i);
398             buf := DupeString(sheed, FCutoffNum);
399             if AnsiContainsText(line, buf) = true then begin
400                 ret := true;
401                 break;
402             end;
403         end;
404     end;
405     Result := ret;
406 end;
407 //\96\96\94ö\82Ì\83u\81[\83\8b\92l\82Ítrue\82¾\82Æ\81ANG\83\8f\81[\83h\82ð\8aÜ\82Þ\82à\82Ì\82¾\82¯\82ð\95Ô\82·\81B
408 procedure TAbon.Execute(var ThreadStrings : TStringList);
409 var
410     i : Integer;
411     NGwordsLine : Integer;
412     bufline : String;
413     invisi : Boolean;
414 begin
415     //FRetStrings.Clear;
416 {
417     if not ReturnNGwordLineNum then begin
418     //if ReturnNGwordLineNum then begin
419         for i:=0 to ThreadStrings.Count - 1 do begin
420                 if FindNGwords(ThreadStrings.Strings[i]) <> Reverse  then begin
421                 if not SetNGResAnchor then
422                         ThreadStrings.Strings[i] := FAbonString
423                 else
424                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(i+1)]);
425                 end else begin
426                 bufline := ThreadStrings.Strings[i];
427                 if Deleterlo = true then begin
428                         bufline := AnsiReplaceText( bufline,'&rlo;','' );
429                     bufline := AnsiReplaceText( bufline,'&lro;','' );
430                 end;
431                 if Replaceul = true then begin
432                         bufline := AnsiReplaceText( bufline,'<ul>','<br>' );
433                         bufline := AnsiReplaceText( bufline,'</ul>','<br>' );
434                 end;
435                 ThreadStrings.Strings[i] := bufline;
436                 end;
437         end;
438     end else begin
439 }
440         for i:=0 to ThreadStrings.Count - 1 do begin
441             NGwordsLine := 0;
442                 if FindNGwords(ThreadStrings.Strings[i], NGwordsLine ,invisi) <> Reverse  then begin
443                 if invisi = true then begin
444                         ThreadStrings.Strings[i] := '';
445                 end else begin
446                     if not ReturnNGwordLineNum and not SetNGResAnchor then begin
447                         ThreadStrings.Strings[i] := FAbonString;
448                     end else if not ReturnNGwordLineNum then begin
449                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(i+1)]);
450                     end else if not SetNGResAnchor then begin
451                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B><><>',[NGwordsLine]);
452                     end else begin
453                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B>&gt;%d <><>',[NGwordsLine,(i+1)]);
454                     end;
455                 end;
456
457                 {
458                 if not SetNGResAnchor then
459                     ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B><><>',[NGwordsLine])
460                 else
461                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B>&gt;%d <><>',[NGwordsLine,(i+1)]);
462                 }
463                 end else begin
464                 bufline := ThreadStrings.Strings[i];
465                 if Deleterlo = true then begin
466                         bufline := AnsiReplaceText( bufline,'&rlo;','' );
467                     bufline := AnsiReplaceText( bufline,'&lro;','' );
468                 end;
469                 if Replaceul = true then begin
470                         bufline := AnsiReplaceText( bufline,'<ul>','<br>' );
471                         bufline := AnsiReplaceText( bufline,'</ul>','<br>' );
472                 end;
473                 ThreadStrings.Strings[i] := bufline;
474                 end;
475         end;
476
477 //    end;
478
479 end;
480 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStringList);
481 var
482     i : Integer;
483 begin
484     SetLength(Ftokens,NGwords.Count);
485     for i := 0  to NGwords.Count -1 do begin
486         SetTokens(i , NGwords.Strings[i]);
487     end;
488     Execute(ThreadStrings);
489
490 end;
491 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStrings);
492 var
493     i : Integer;
494     buf : TStringList;
495 begin
496     buf := TStringList.Create;
497     buf.AddStrings(NGwords);
498     SetLength(Ftokens,buf.Count);
499     for i := 0  to buf.Count -1 do begin
500         SetTokens(i , buf.Strings[i]);
501     end;
502     Execute(ThreadStrings);
503     buf.Free;
504 end;
505
506
507 //****************************************************************************//
508 //DAT\82ð\92¼\82É\82¢\82\82é\93z\82ç===========================================================
509 //NG\83\8f\81[\83h\82ð\8aÜ\82Þ\83\8c\83X\82Ì\90æ\93ª\82É\82 \82Ú\81[\82ñ\82ð\91}\93ü
510 function TAbon.ExecuteFile(datfilepath : String; NGwordpath : String) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
511 var
512     datstl : TStringList;
513     ret : Boolean;
514     i : Integer;
515 begin
516     datstl := TStringList.Create;
517     ret := true;
518     try
519         try
520             datstl.LoadFromFile(datfilepath);
521             for i := 0 to datstl.Count -1 do begin
522                 if FindNGwords(datstl.Strings[i]) = true  then begin
523                     datstl.Strings[i] := FAbonString + datstl.Strings[i]
524                 end;
525             end;
526
527             datstl.SaveToFile(datfilepath);
528         except
529             ret := false;
530         end;
531     finally
532         datstl.Free;
533     end;
534     Result := ret;
535
536 end;
537 //\8ew\92è\82³\82ê\82½\83\8c\83X\94Ô\82Ì\90æ\93ª\82É\82 \82Ú\81[\82ñ\91}\93ü
538 function TAbon.ExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
539 var
540     datstl : TStringList;
541     ret : Boolean;
542 begin
543     ret := true;
544     datstl := TStringList.Create;
545     try
546         try
547             datstl.LoadFromFile(datfilepath);
548             if (resnum > 0) and (resnum <= datstl.Count) then begin
549                 if AnsiPos(FAbonString, datstl.Strings[resnum-1]) <> 1 then begin
550                     datstl.Strings[resnum-1] := FAbonString + datstl.Strings[resnum-1];
551                 end;
552             end;
553             datstl.SaveToFile(datfilepath);
554         except
555             ret := false;
556         end;
557     finally
558         datstl.Free;
559     end;
560     Result := ret;
561 end;
562 //firstres\82©\82çcount\8cÂ\82Ì\83\8c\83X\82Ì\90æ\93ª\82É\82 \82Ú\81[\82ñ\91}\93ü
563 function TAbon.ExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
564 var
565     datstl : TStringList;
566     i : Integer;
567     endnum : Integer; //\8fI\82í\82è\82Ì\83\8c\83X\94Ô
568     ret : Boolean;
569 begin
570     ret := true;
571     datstl := TStringList.Create;
572     try
573         try
574             datstl.LoadFromFile(datfilepath);
575             if (firstres > 0) and (firstres <= datstl.Count) then begin
576                 if firstres + count -1 > datstl.Count then begin
577                     endnum := datstl.Count;
578                 end else if count <= 0 then begin
579                     endnum := firstres + 1;
580                 end else begin
581                     endnum := firstres + count -1;
582                 end;
583
584                 for i := firstres to endnum do begin
585                     if AnsiPos(FAbonString, datstl.Strings[i-1]) <> 1 then begin
586                         datstl.Strings[i-1] := FAbonString + datstl.Strings[i-1];
587                     end;
588                 end;
589             end;
590             datstl.SaveToFile(datfilepath);
591         except
592             ret := false;
593         end;
594     finally
595         datstl.Free;
596     end;
597     Result := ret;
598 end;
599 //DAT\82ð\92¼\82É\82¢\82\82é\93z\82ç==========\82±\82±\82Ü\82Å=========================================
600
601 //\8c³\82É\96ß\82·\93z\82ç==================================================================
602 function TAbon.ReverseExecuteFile(datfilepath : String) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
603 var
604     datstl : TStringList;
605     i : Integer;
606     buf : String;
607     ret : Boolean;
608 begin
609     ret := true;
610     datstl := TStringList.Create;
611     try
612         try
613             datstl.LoadFromFile(datfilepath);
614             for i:=0 to datstl.Count -1  do begin
615                 if AnsiPos(FAbonString, datstl.Strings[i]) = 1 then begin
616                     buf := datstl.Strings[i];
617                     Delete(buf,1,Length(FAbonString));
618                     datstl.Strings[i] := buf;
619                 end;
620             end;
621             datstl.SaveToFile(datfilepath);
622         except
623             ret := false;
624         end;
625     finally
626         datstl.Free;
627     end;
628     Result := ret;
629
630 end;
631 function TAbon.ReverseExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
632 var
633     datstl : TStringList;
634     buf : String;
635     ret : Boolean;
636 begin
637     ret := true;
638     datstl := TStringList.Create;
639     try
640         try
641             datstl.LoadFromFile(datfilepath);
642             if (resnum > 0) and (resnum <= datstl.Count) then begin
643                 if AnsiPos(FAbonString, datstl.Strings[resnum-1]) = 1 then begin
644                     buf := datstl.Strings[resnum-1];
645                     Delete(buf,1,Length(FAbonString));
646                     datstl.Strings[resnum-1] := buf;
647                 end;
648             end;
649             datstl.SaveToFile(datfilepath);
650         except
651             ret := false;
652         end;
653     finally
654         datstl.Free;
655     end;
656     Result := ret;
657
658 end;
659 function TAbon.ReverseExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean;//DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
660 var
661     datstl : TStringList;
662     i : Integer;
663     endnum : Integer; //\8fI\82í\82è\82Ì\83\8c\83X\94Ô
664     buf : String;
665     ret : Boolean;
666 begin
667     ret := true;
668     datstl := TStringList.Create;
669     try
670         try
671             datstl.LoadFromFile(datfilepath);
672             if (firstres > 0) and (firstres <= datstl.Count) then begin
673                 if firstres + count -1 > datstl.Count then begin
674                     endnum := datstl.Count;
675                 end else if count <= 0 then begin
676                     endnum := firstres + 1;
677                 end else begin
678                     endnum := firstres + count -1;
679                 end;
680                 for i := firstres to endnum do begin
681                     if AnsiPos(FAbonString, datstl.Strings[i-1]) = 1 then begin
682                         buf := datstl.Strings[i-1];
683                         Delete(buf,1,Length(FAbonString));
684                         datstl.Strings[i-1] := buf;
685                     end;
686                 end;
687             end;
688             datstl.SaveToFile(datfilepath);
689         except
690             ret := false;
691         end;
692     finally
693         datstl.Free;
694     end;
695     Result := ret;
696 end;
697 //\8c³\82É\96ß\82·\93z\82ç=================\82±\82±\82Ü\82Å=========================================
698 //\8c»\8dÝ\83Z\83b\83g\82³\82ê\82Ä\82¢\82éNGword.txt\82ð\8aJ\82­
699 procedure TAbon.EditNGwords();
700 begin
701     ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
702 end;
703 //\83|\83b\83v\83A\83b\83v\97p\94»\92è\8aÖ\90\94
704 function TAbon.CheckAbonPopupRes(line : String) :Boolean;
705 begin
706     if AbonPopupRes = true then begin
707         Result := FindNGwords(line);
708     end else begin
709         Result := false;
710     end;
711 end;
712 //\95¡\90\94\82ÌNG\83\8f\81[\83h\83e\83L\83X\83g\82ð\93Ç\82Ý\8d\9e\82Þ==============================================
713 //List\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
714 function TAbon.LoadListFile(path :String; listStringList : TStringList) : Boolean;
715 begin
716     try
717         listStringList.LoadFromFile(path);
718         Result := true;
719     except
720         listStringList.Append('\88ê\94Ê=NGword.txt');
721         listStringList.SaveToFile(path);
722         Result := false;
723     end;
724 end;
725 //List\82Ì\88ê\82Â\8e\9f\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
726 function TAbon.GoForward() : Boolean;
727 begin
728     FNGwordFileIndex := FNGwordFileIndex + 1;
729     Result := ReadNGwordslist(FNGwordFileIndex);
730 end;
731 //List\82Ì\88ê\82Â\91O\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
732 function TAbon.GoBack() : Boolean;
733 begin
734     FNGwordFileIndex := FNGwordFileIndex -1;
735     Result := ReadNGwordslist(FNGwordFileIndex);
736 end;
737 //List\82Ì\82P\8ds\96Ú\82ð\93Ç\82Þ
738 procedure TAbon.GoHome();
739 begin
740     FNGwordFileIndex := 0;
741     ReadNGwordslist(FNGwordFileIndex);
742 end;
743 //List\82Ìline\8ds\96Ú\82ð\93Ç\82Þ
744 function TAbon.ReadNGwordslist(line : Integer) : Boolean;
745 var
746     liststl : TStringList;
747     linebuf : String;
748 begin
749     liststl := TStringList.Create;
750     try
751         if LoadListFile(Flistpath,liststl) = true then begin
752             if line < 0 then begin
753                 line := liststl.Count - 1;
754                 FNGwordFileIndex := liststl.Count - 1;
755             end else if line > liststl.Count - 1 then begin
756                 line := 0;
757                 FNGwordFileIndex := 0;
758             end;
759             linebuf := liststl.Strings[line];
760             FNGwordname := Copy(linebuf,1,AnsiPos('=',linebuf)-1);
761             Delete(linebuf,1,AnsiPos('=',linebuf));
762             SetNGwordpath(linebuf);
763             Result := true;
764         end else begin
765             Result := false;
766         end
767     finally
768         liststl.Free;
769     end;
770
771 end;
772 //\95¡\90\94\82ÌNG\83\8f\81[\83h\83e\83L\83X\83g\82ð\93Ç\82Ý\8d\9e\82Þ=====\82±\82±\82Ü\82Å=================================
773 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\8eÀ\8ds\8aÖ\90\94
774 procedure TAbon.IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String);
775 var
776         i : Integer;
777 begin
778         if FileExists(SetResNumFile) = true then begin
779         if LoadFromSetResNumFile(SetResNumFile) = true then begin
780                 for i := 0 to High(FAbonRes) do begin
781                  if (FAbonRes[i].Res <= ThreadStrings.Count) and (FAbonRes[i].Res > 0) then begin
782                         if FAbonRes[i].option = 0 then begin
783                         ThreadStrings.Strings[FAbonRes[i].Res-1] := '';
784                     end else begin
785                         ThreadStrings.Strings[FAbonRes[i].Res-1] := '\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>';
786                     end;
787                  end;
788
789             end;
790         end;
791     end else begin
792         FIndividualFileName := SetResNumFile;
793         SetLength(FAbonRes,1);
794         FAbonRes[0].Res := 0;
795         FAbonRes[0].option := -1;
796     end;
797 end;
798 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý\8aÖ\90\94
799 function TAbon.LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
800 var
801         bufStringList : TStringList;
802     bufLine : String;
803     i : Integer;
804 begin
805     bufStringList := TStringList.Create;
806     try
807         try
808                 bufStringList.LoadFromFile(SetResNumFile);
809             FIndividualFileName := SetResNumFile;
810             //\8bó\8ds\8dí\8f\9c
811             for i := bufStringList.Count-1 downto 0 do begin
812                         if bufStringList.Strings[i] = '' then begin
813                         bufStringList.Delete(i);
814                     end;
815             end;
816
817             //\83\81\83\82\83\8a\8am\95Û
818                 SetLength(FAbonRes,bufStringList.Count);
819             //\91ã\93ü
820             for i :=0 to bufStringList.Count - 1 do begin
821                         bufLine := Trim(bufStringList.Strings[i]);
822                     FAbonRes[i].Res :=  StrToInt(Copy(bufLine,1,AnsiPos('-',bufLine)-1));
823                 FAbonRes[i].option := StrToInt(Copy(bufLine,AnsiPos('-',bufLine)+1,1));
824             end;
825         except
826                 Result := false;
827             Exit;
828         end;
829     finally
830         bufStringList.Free;
831     end;
832     Result := true;
833 end;
834 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\82É\92Ç\89Á
835 procedure TAbon.AddIndividualAbon( ResNum : Integer ; option : Integer);
836 var
837         IndividualFile : TStringList;
838     linebuf : String;
839     i : Integer;
840 begin
841     IndividualFile := TStringList.Create;
842         if FAbonRes[0].Res <> 0 then begin
843         for i := 0 to High(FAbonRes) do begin
844             if FAbonRes[i].Res <> ResNum then begin
845                         linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
846                 IndividualFile.Append(linebuf);
847             end;
848         end;
849     end;
850     linebuf := IntToStr(ResNum) + '-' + IntToStr(option);
851     IndividualFile.Append(linebuf);
852     try
853         IndividualFile.SaveToFile(FIndividualFileName);
854     finally
855         IndividualFile.Free;
856     end;
857 end;
858 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\82©\82ç\8dí\8f\9c
859 procedure TAbon.DeleteIndividualAbon( ResNum : Integer);
860 var
861         IndividualFile : TStringList;
862     linebuf : String;
863     i : Integer;
864 begin
865     IndividualFile := TStringList.Create;
866         if FAbonRes[0].Res <> 0 then begin
867         for i := 0 to High(FAbonRes) do begin
868             if FAbonRes[i].Res <> ResNum then begin
869                         linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
870                 IndividualFile.Append(linebuf);
871             end;
872         end;
873     end;
874         if IndividualFile.Count <> 0 then begin
875         try
876                 IndividualFile.SaveToFile(FIndividualFileName);
877         finally
878                 IndividualFile.Free;
879         end;
880     end else begin
881         if FileExists(FIndividualFileName) = true then begin
882                 DeleteFile(FIndividualFileName);
883         end;
884     end;
885 end;
886 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82Ì\83\8a\83X\83g\82Ì\8cÂ\90\94\82ð\95Ô\82·
887 function TAbon.GetAbonResCount() : Integer;
888 var
889         i : Integer;
890 begin
891     if FAbonRes[0].Res = 0 then begin
892         Result := 0
893     end else begin
894                 i := High(FAbonRes);
895         Result := i+1;
896     end;
897 end;
898 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82Ì\83\8a\83X\83g\82Ì\82\8e\8ds\96Ú\82Ì\83\8c\83X\82ð\95\8e\9a\97ñ\82Å\95Ô\82·
899 function TAbon.GetAbonResString(Num : Integer) : String;
900 begin
901         if (Num <= High(FAbonRes)) and (Num >= 0) then begin
902         Result := IntToStr(FAbonRes[Num].Res);
903     end else begin
904         Result := '';
905     end;
906 end;
907 //\83|\83b\83v\83A\83b\83v\82Ì\94»\92è\97p
908 function TAbon.CheckIndividualAbonList(ResNum : Integer) : Boolean;
909 var
910         i : Integer;
911 begin
912         if FAbonRes[0].Res <> 0 then begin
913         for i := 0 to High(FAbonRes) do begin
914                 if FAbonRes[i].Res = ResNum then begin
915                 Result := true;
916                 Exit;
917             end;
918         end;
919     end;
920     Result := false;
921     
922 end;
923 end.
924