OSDN Git Service

まちBBSで削除レスがあるレス番号とスレの件数がずれる不具合を修正
[gikonavigoeson/gikonavi.git] / InputAssistDataModule.pas
index 5f69086..1b6f584 100644 (file)
@@ -3,7 +3,7 @@ unit InputAssistDataModule;
 interface
 
 uses
-  SysUtils, Classes;
+  SysUtils, Classes, Windows;
 
 type
   TResistWord = class;
@@ -15,6 +15,7 @@ type
        { Private \90é\8c¾ }
        FInit : Boolean;
        FDictionary : TStringList;      ///< \93o\98^\92P\8cê\82Æ\92è\8c^\95\82Ì\8e«\8f\91
+       FSorted : Boolean;
        function GetSorted: Boolean;    ///< \83\\81[\83g\82Ì\8fó\91Ô\82Ì\8eæ\93¾
        procedure SetSorted(Value: Boolean);    ///< \83\\81[\83g\8fó\91Ô\82Ì\90Ý\92è
 
@@ -36,6 +37,8 @@ type
        function GetCategoryResistWords(Key: String; var list: TStringList): Integer;
        //! \93o\98^\8dÏ\82Ý\83L\81[\82Ì\91S\82Ä\82Ì\83J\83e\83S\83\8a\83\8a\83X\83g\8eæ\93¾
        procedure GetCategoryList(var list: TStringList);
+       //! \8aù\82É\93o\98^\8dÏ\82Ý\82Ì\83L\81[\82Æ\83J\83e\83S\83\8a\82Ì\83Z\83b\83g\82©\82Ç\82¤\82©\83`\83F\83b\83N
+       function IsDupulicate(Key: String; Category: String): Boolean;
 
   end;
 
@@ -57,6 +60,7 @@ type
   end;
 
   function CategorySort(List: TStringList; Index1, Index2: Integer): Integer;
+  function KeySort(List: TStringList; Index1, Index2: Integer): Integer;
 var
   InputAssistDM: TInputAssistDM;
 
@@ -118,7 +122,7 @@ begin
        try
                // \83t\83@\83C\83\8b\82Ì\91\8dÝ\82ð\8am\94F
                if FileExists(FilePath) then begin
-                       ini := TMemIniFile.Create(FilePath);
+            ini := TMemIniFile.Create(FilePath);
                        sections := TStringList.Create;
                        keys := TStringList.Create;
                        try
@@ -140,6 +144,9 @@ begin
                                sections.Free;
                                ini.Free;
                        end;
+                       if FSorted Then begin
+                               FDictionary.CustomSort(KeySort);
+                       end;
                end;
 
        except
@@ -155,10 +162,11 @@ var
 begin
        if FileExists(FilePath) then begin
                try
-                       DeleteFile(FilePath);
+                       SysUtils.DeleteFile(FilePath);
                except
                end;
        end;
+
        ini := TMemIniFile.Create(FilePath);
        try
                for i :=0 to FDictionary.Count - 1 do begin
@@ -188,8 +196,8 @@ end;
 procedure TInputAssistDM.DataModuleCreate(Sender: TObject);
 begin
        FDictionary := TStringList.Create;
-       FDictionary.Duplicates := dupAccept;
-       FDictionary.Sorted := True;
+       FDictionary.Sorted := False;
+       FSorted := True;
 end;
 //! \93o\98^\92P\8cê\90\94\8eæ\93¾
 function TInputAssistDM.ResistWordCount : Integer;
@@ -222,6 +230,9 @@ begin
                                break;
                        end;
                end;
+               if FSorted Then begin
+                       FDictionary.CustomSort(KeySort);
+               end;
        end;
 end;
 //! \93o\98^\92P\8cê\92Ç\89Á
@@ -237,6 +248,9 @@ begin
                resWord.SetText('\92è\8c^\95¶');
                FDictionary.AddObject(Key, resWord);
                Result := resWord;
+               if FSorted Then begin
+                       FDictionary.CustomSort(KeySort);
+               end;
        end;
 end;
 //! \93o\98^\92P\8cê\82Ì\83L\81[\95Ï\8dX
@@ -251,6 +265,10 @@ begin
                                break;
                        end;
                end;
+               if FSorted Then begin
+                       FDictionary.CustomSort(KeySort);
+               end;
+
        end;
 end;
 //! Key\82ð\8e\9d\82Â\93o\98^\82³\82ê\82Ä\82¢\82é\92P\8cê\82ð\8eæ\93¾
@@ -300,17 +318,15 @@ end;
 //! \83\\81[\83g\82Ì\8fó\91Ô\82Ì\8eæ\93¾
 function TInputAssistDM.GetSorted: Boolean;
 begin
-       Result := False;
-       if (FDictionary <> nil) then begin
-               Result := FDictionary.Sorted;
-       end;
+       Result := FSorted;
 end;
 //! \83\\81[\83g\8fó\91Ô\82Ì\90Ý\92è
 procedure TInputAssistDM.SetSorted(Value: Boolean);
 begin
-       if (FDictionary <> nil) then begin
-               FDictionary.Sorted := Value;
+       if (not FSorted) and (Value) then begin
+               FDictionary.CustomSort(KeySort);
        end;
+       FSorted := Value;
 end;
 //! Key\82Ì\83J\83e\83S\83\8a\82É\93o\98^\82³\82ê\82Ä\82¢\82é\92P\8cê\82ð\8eæ\93¾
 function TInputAssistDM.GetCategoryResistWords(Key: String; var list: TStringList): Integer;
@@ -360,12 +376,51 @@ begin
        try
                resWord1 := TResistWord(List.Objects[Index1]);
                resWord2 := TResistWord(List.Objects[Index2]);
-               Result := AnsiCompareStr(resWord1.GetCategory, resWord2.GetCategory);
+               Result := CompareStr(ZenToHan(resWord1.GetCategory),
+                                                                ZenToHan(resWord2.GetCategory));
                if (Result = 0) then begin
-                       Result := AnsiCompareStr(resWord1.GetKey, resWord2.GetKey);
+                       Result := CompareStr(ZenToHan(resWord1.GetKey),
+                                                                        ZenToHan(resWord2.GetKey));
                end;
        except
        end;
 end;
+//! Key\82ð\91S\94¼\8ap\96³\8e\8b\82Ì\8c`\82Å\83\\81[\83g\82·\82é\8dÛ\82Ì\94ä\8ar\83\81\83\\83b\83h
+function KeySort(List: TStringList; Index1, Index2: Integer): Integer;
+var
+       resWord1 : TResistWord;
+       resWord2 : TResistWord;
+begin
+       Result := 0;
+       try
+               resWord1 := TResistWord(List.Objects[Index1]);
+               resWord2 := TResistWord(List.Objects[Index2]);
+               Result := CompareStr(ZenToHan(resWord1.FKey),
+                                                                ZenToHan(resWord2.FKey));
+               if (Result = 0) then begin
+                       Result := CompareStr(ZenToHan(resWord1.GetCategory),
+                                                                        ZenToHan(resWord2.GetCategory));
+               end;
+       except
+       end;
+end;
+//! \8aù\82É\93o\98^\8dÏ\82Ý\82Ì\83L\81[\82Æ\83J\83e\83S\83\8a\82Ì\83Z\83b\83g\82©\82Ç\82¤\82©\83`\83F\83b\83N
+function TInputAssistDM.IsDupulicate(Key: String; Category: String): Boolean;
+var
+       i : Integer;
+begin
+       // \82±\82Ì\83\81\83\\83b\83h\82Å\82Í\81A\83\\81[\83g\8dÏ\82Ý\82Æ\82Í\8cÀ\82ç\82È\82¢\82Ì\82Å\81A\91S\82Ä\82Ì\83L\81[\82ð\92T\8dõ\82µ\82Ä\82¢\82é
+       Result := False;
+       if (FDictionary <> nil) then begin
+               for i := 0 to FDictionary.Count - 1 do begin
+                       if (Key = FDictionary.Strings[i]) and
+                               (Category = TResistWord(FDictionary.Objects[i]).GetCategory)
+                       then begin
+                               Result := True;
+                               Break;
+                       end;
+               end;
+       end;
+end;
 
 end.