OSDN Git Service

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