Develop and Download Open Source Software

Browse CVS Repository

Diff of /gikonavigoeson/gikonavi/AbonUnit.pas

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

revision 1.8 by h677, Mon Aug 18 08:13:38 2003 UTC revision 1.9 by h677, Mon Aug 18 12:50:03 2003 UTC
# Line 9  type Line 9  type
9    private    private
10      { Private 宣言 }      { Private 宣言 }
11      Froot : String;      Froot : String;
12        Flistpath : String;
13      FNGwordpath : String;      FNGwordpath : String;
14      Ftokens : array of array of string;      Ftokens : array of array of string;
15      FAbonString : String;      FAbonString : String;
# Line 18  type Line 19  type
19      FReverse : Boolean ;  //NGワードでのあぼ〜んの結果を反転させるか      FReverse : Boolean ;  //NGワードでのあぼ〜んの結果を反転させるか
20      FAbonPopupRes : Boolean; //レスポップアップの時にあぼーんするか      FAbonPopupRes : Boolean; //レスポップアップの時にあぼーんするか
21      FCreateNGwordFile : Boolean; //指定されたpathにNGワードtxtが無かったときに自動的に生成するか      FCreateNGwordFile : Boolean; //指定されたpathにNGワードtxtが無かったときに自動的に生成するか
22        FNGwordFileIndex : Integer; //現在読み込んでるNGワードがlistの何行目か
23        FNGwordname : String; //現在読み込んでるNGワードの表示名
24      procedure SetTokens(index: integer ; argline:String);      procedure SetTokens(index: integer ; argline:String);
25        function Getlistpath() : String;
26        procedure Setlistpath(const Value : String);
27        function LoadListFile(path :String;listStringList : TStringList) : Boolean;
28        
29    public    public
30      { Public 宣言 }      { Public 宣言 }
31      constructor Create; // コンストラクタ      constructor Create; // コンストラクタ
# Line 30  type Line 36  type
36      property CreateNGwordFile: Boolean read FCreateNGwordFile write FCreateNGwordFile;      property CreateNGwordFile: Boolean read FCreateNGwordFile write FCreateNGwordFile;
37      property AbonString : String read FAbonString write FAbonString;      property AbonString : String read FAbonString write FAbonString;
38      property  AbonPopupRes : Boolean read FAbonPopupRes write FAbonPopupRes default false;      property  AbonPopupRes : Boolean read FAbonPopupRes write FAbonPopupRes default false;
39        property listpath : String read Getlistpath write Setlistpath;
40        property NGwordFileIndex : Integer read FNGwordFileIndex write FNGwordFileIndex default 0;
41        property NGwordname : String read FNGwordname write FNGwordname;
42      procedure Setroot(root :String);      procedure Setroot(root :String);
43      function Getroot() : String;      function Getroot() : String;
44    
45        function Getfullpath(argpath : String) : String;
46      procedure SetNGwordpath(path :String);      procedure SetNGwordpath(path :String);
47      function GetNGwordpath() : String;      function GetNGwordpath() : String;
48      function LoadFromNGwordFile(path :String) : Boolean;      function LoadFromNGwordFile(path :String) : Boolean;
# Line 54  type Line 65  type
65      //--      //--
66      procedure EditNGwords();  //NGword.txtを開く。      procedure EditNGwords();  //NGword.txtを開く。
67      function ShowAllTokens() : String;  //デバッグ用      function ShowAllTokens() : String;  //デバッグ用
68        //--
69        procedure GoHome();//Listの1行目を読む
70        function GoForward() : Boolean; //Listの一つ次のNGワードファイルを読み込む
71        function GoBack() : Boolean; //Listの一つ前のNGワードファイルを読み込む
72    end;    end;
73  var  var
74      Abon1 :TAbon;      Abon1 :TAbon;
75    const
76        NGwordListFileName : String = 'NGwords.list';
77    
78  implementation  implementation
79    
# Line 74  end; Line 91  end;
91    
92    
93    
94  //rootはExeのいるフォルダ  //rootはExe\config\NGwordsフォルダ
95  procedure TAbon.Setroot(root :String);  procedure TAbon.Setroot(root :String);
96    var
97        bufStringList : TStringList;
98  begin  begin
99        bufStringList := TStringList.Create;
100        try
101            if not DirectoryExists(root) then begin
102                CreateDir(root);
103            end;
104            if root[Length(root)] <> '\' then begin
105                root := root + '\';
106            end;
107            Flistpath := root + NGwordListFileName;
108            LoadListFile(Flistpath, bufStringList);
109        finally
110            bufStringList.Free;
111        end;
112      Froot := root;      Froot := root;
113  end;  end;
114  function TAbon.Getroot() : String;  function TAbon.Getroot() : String;
# Line 86  end; Line 118  end;
118  //NGwordpathはNGword.txtのフルパス  //NGwordpathはNGword.txtのフルパス
119  procedure TAbon.SetNGwordpath(path :String);  procedure TAbon.SetNGwordpath(path :String);
120  begin  begin
121      FNGwordpath := path;      FNGwordpath := Getfullpath(path);
122      LoadFromNGwordFile(FNGwordpath);      LoadFromNGwordFile(FNGwordpath);
123  end;  end;
124  function TAbon.GetNGwordpath() : String;  function TAbon.GetNGwordpath() : String;
125  begin  begin
126      Result :=  FNGwordpath;      Result :=  FNGwordpath;
127  end;  end;
128  //NGwordファイルの読み込み  //フルパスでなければフルパスにして返す。
129  function TAbon.LoadFromNGwordFile(path :String) : boolean;  function TAbon.Getfullpath(argpath : String) : String;
 var  
     bufstl : TStringList;  
     i : integer;  
130  begin  begin
131      if AnsiPos(':\',path) <> 2 then begin  //ドライブからのフルパスが無ければ      if AnsiPos(':\',argpath) <> 2 then begin  //ドライブからのフルパスが無ければ
132          if Getroot() = '' then begin          if Getroot() = '' then begin
133              Result := false;    //rootパスが設定されてないからfalse              Result := '';    //rootパスが設定されてないか空にする
             Exit;  
134          end else begin          end else begin
135              if (Froot[Length(Froot)] = '\') and (path[1] = '\') then begin  //先頭の\を削除              if (Froot[Length(Froot)] = '\') and (argpath[1] = '\') then begin  //先頭の\を削除
136                  Delete(path,1,1);                  Delete(argpath,1,1);
137              end;              end;
138              Insert( Getroot(), path , 1);//rootパスを挿入              Insert( Getroot(), argpath , 1);//rootパスを挿入
139                Result := argpath;
140          end;          end;
141        end else begin
142            Result := argpath;
143      end;      end;
     bufstl := TStringList.Create;  
     try  
         bufstl.LoadFromFile(path);  
         LoadFromStringList( bufstl );  
144    
145      except  end;
146          if CreateNGwordFile = true then begin  //NGwordファイルの読み込み
147              bufstl.SaveToFile(path);  function TAbon.LoadFromNGwordFile(path :String) : boolean;
148          end;  var
149          bufstl.Free;      bufstl : TStringList;
150    begin
151        path := Getfullpath(path);
152        if path = '' then begin
153          Result := false;          Result := false;
154          Exit;      end else begin
155            bufstl := TStringList.Create;
156            try
157                try
158                    bufstl.LoadFromFile(path);
159                    LoadFromStringList( bufstl );
160                    Result := true;
161                except
162                    if CreateNGwordFile = true then begin
163                        bufstl.SaveToFile(path);
164                    end;
165                    Result := false;
166                end;
167            finally
168                bufstl.Free;
169            end;
170      end;      end;
171      bufstl.Free;  
     Result := true;  
172  end;  end;
173  //NGwordリスト読み込み  //NGwordリスト読み込み
174  procedure TAbon.LoadFromStringList( bufstl : TStringList );  procedure TAbon.LoadFromStringList( bufstl : TStringList );
# Line 155  begin Line 199  begin
199          Result := LoadFromNGwordFile( GetNGwordpath() );          Result := LoadFromNGwordFile( GetNGwordpath() );
200      end;      end;
201  end;  end;
202    function TAbon.Getlistpath() : String;
203    begin
204        Result := Flistpath;
205    end;
206    procedure TAbon.Setlistpath(const Value : String);
207    begin
208        Flistpath := Getfullpath(Value);
209    end;
210  //一行の中のトークンを切り分けてセット  //一行の中のトークンを切り分けてセット
211  procedure TAbon.SetTokens(index: integer ; argline : String);  procedure TAbon.SetTokens(index: integer ; argline : String);
212  var  var
# Line 243  end; Line 294  end;
294  procedure TAbon.Execute(var ThreadStrings : TStringList);  procedure TAbon.Execute(var ThreadStrings : TStringList);
295  var  var
296      i : Integer;      i : Integer;
     j : Integer;  
297      bufline : String;      bufline : String;
298  begin  begin
299      //FRetStrings.Clear;      //FRetStrings.Clear;
# Line 489  begin Line 539  begin
539      ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);      ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
540  end;  end;
541  function TAbon.CheckAbonPopupRes(line : String) :Boolean;  function TAbon.CheckAbonPopupRes(line : String) :Boolean;
 var  
     i : Integer;  
542  begin  begin
543      if FCutoffNum  = 0 then begin      if AbonPopupRes = true then begin
544          if AbonPopupRes = true then begin          Result := FindNGwords(line);
             Result := FindNGwords(line);  
         end else begin  
             Result := false;  
         end;  
545      end else begin      end else begin
546          if AbonPopupRes = true then begin          Result := false;
547              Result := FindNGwords(line);      end;
548              if Result = false then begin  end;
549                  for i := 0 to 2 do begin  //Listファイルを読み込む
550                      Delete(line,1,Ansipos('<>',line)+1);  function TAbon.LoadListFile(path :String; listStringList : TStringList) : Boolean;
551                  end;  begin
552                  Delete(line,Ansipos('<>',line),Length(line)-Ansipos('<>',line)+1);      try
553                  Result := Cutoff(line);          listStringList.LoadFromFile(path);
554              end;          Result := true;
555          end else begin      except
556              Result := false;          listStringList.Append('一般=NGword.txt');
557          end;          listStringList.SaveToFile(path);
558            Result := false;
559      end;      end;
560  end;  end;
561    //Listの一つ次のNGワードファイルを読み込む
562    function TAbon.GoForward() : Boolean;
563    var
564        liststl : TStringList;
565        linebuf : String;
566    begin
567        liststl := TStringList.Create;
568        try
569            if LoadListFile(Flistpath,liststl) = true then begin
570                FNGwordFileIndex := FNGwordFileIndex + 1;
571                if FNGwordFileIndex > liststl.Count -1 then begin
572                    FNGwordFileIndex := 0;
573                end;
574                linebuf := liststl.Strings[FNGwordFileIndex];
575                FNGwordname := Copy(linebuf,1,AnsiPos('=',linebuf)-1);
576                Delete(linebuf,1,AnsiPos('=',linebuf));
577    
578                SetNGwordpath(linebuf);
579                Result := true;
580            end else begin
581                Result := false;
582            end
583        finally
584            liststl.Free;
585        end;
586    
587    end;
588    //Listの一つ前のNGワードファイルを読み込む
589    function TAbon.GoBack() : Boolean;
590    begin
591        FNGwordFileIndex := FNGwordFileIndex -2;
592        if FNGwordFileIndex < -1 then FNGwordFileIndex := 0;
593        Result := GoForward()
594    end;
595    //Listの1行目を読む
596    procedure TAbon.GoHome();
597    begin
598        FNGwordFileIndex := -1;
599        GoForward();
600    end;
601  end.  end.
602    

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

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