OSDN Git Service

TReplacePairRecは外部から使わないように変更し、TReplacePairを使うように修正。メモリ解放周りにバグあるかも
authornaru <bottle@mikage.to>
Fri, 19 Mar 2004 05:39:28 +0000 (05:39 +0000)
committernaru <bottle@mikage.to>
Fri, 19 Mar 2004 05:39:28 +0000 (05:39 +0000)
bottleclient/MainForm.pas
bottleclient/StrReplace.pas
bottleclient/StrReplaceDialog.pas
bottleclient/StrReplaceFrame.pas

index 9670cc8..3019767 100755 (executable)
@@ -2846,15 +2846,13 @@ procedure TfrmSender.actReplaceExecute(Sender: TObject);
 var
   Form: TfrmStrReplaceDialog;
   Lines: String;
-  Pair: TReplacePairRec;
   Options: TReplaceFlags;
 begin
   Application.CreateForm(TfrmStrReplaceDialog, Form);
   try
     if Form.Execute then
     begin
-      Pair := Form.PairRec;
-      with Pair do
+      with Form.Pair do
       begin
         Lines := memScript.Lines.Text;
         Options := [rfReplaceAll];
index 1deb1c0..954bd1e 100644 (file)
@@ -43,10 +43,28 @@ type
     property UseRegExp: boolean read GetUseRegExp write SetUseRegExp;
   end;
 
-  // TReplacePair\82Ì\83R\83\8c\83N\83V\83\87\83\93\83N\83\89\83X
-  TReplacePairCollection = class(TCollection)
+  // TReplacePair\82Ì\83R\83\8c\83N\83V\83\87\83\93\83N\83\89\83X\81B
+  // \82±\82Ì\83\86\83j\83b\83g\82Ì\8aO\82©\82ç\83C\83\93\83X\83^\83\93\83X\89»\82µ\82È\82¢\82±\82Æ
+  TReplacePairCollection = class(TCollection);
+
+  // TReplacePairCollection\82ð\95ï\82Þ\83N\83\89\83X\81B
+  // \82±\82Ì\83\8c\83x\83\8b\82ÅRead/WriteComponent\82ª\89Â\94\\82É\82È\82é\82æ\82¤\82É\82·\82é
+  TReplacePairs = class(TComponent)
+  private
+    FPairs: TReplacePairCollection;
+    procedure SetPairs(const Value: TReplacePairCollection);
+    function GetPair(Index: Integer): TReplacePair;
+    procedure SetPair(Index: Integer; const Value: TReplacePair);
+    function GetCount: Integer;
   public
+    procedure Assign(Source: TPersistent); override;
+    property Pair[Index: Integer]: TReplacePair read GetPair write SetPair;
+    property Count: Integer read GetCount;
     function ExecuteReplace(TargetStr: String): String;
+  published
+    constructor Create(AOwner: TComponent); override;
+    destructor Destroy; override;
+    property Pairs: TReplacePairCollection read FPairs write SetPairs;
   end;
 
   // TReplacePair\82Ì\83R\83\8c\83N\83V\83\87\83\93\82ð\95Û\8e\9d\82µ\81A\83^\83C\83g\83\8b\82È\82Ç\82ð\82Ü\82Æ\82ß\82Ä
@@ -54,9 +72,9 @@ type
   TReplacePreset = class(TCollectionItem)
   private
     FTitle: String;
-    FPairs: TReplacePairCollection;
+    FPairs: TReplacePairs;
     FShortCut: TShortCut;
-    procedure SetPairs(const Value: TReplacePairCollection);
+    procedure SetPairs(const Value: TReplacePairs);
     procedure SetShortCut(const Value: TShortCut);
     procedure SetTitle(const Value: String);
   public
@@ -64,7 +82,7 @@ type
     destructor Destroy; override;
     procedure Assign(Source: TPersistent); override;
   published
-    property Pairs: TReplacePairCollection read FPairs write SetPairs;
+    property Pairs: TReplacePairs read FPairs write SetPairs;
     property Title: String read FTitle write SetTitle;
     property ShortCut: TShortCut read FShortCut write SetShortCut;
   end;
@@ -173,7 +191,7 @@ end;
 constructor TReplacePreset.Create(Collection: TCollection);
 begin
   inherited;
-  FPairs := TReplacePairCollection.Create(TReplacePair);
+  FPairs := TReplacePairs.Create(nil);
 end;
 
 destructor TReplacePreset.Destroy;
@@ -182,7 +200,7 @@ begin
   inherited;
 end;
 
-procedure TReplacePreset.SetPairs(const Value: TReplacePairCollection);
+procedure TReplacePreset.SetPairs(const Value: TReplacePairs);
 begin
   FPairs.Assign(Value);
 end;
@@ -230,19 +248,59 @@ begin
   FPresets.Assign(Value);
 end;
 
-{ TReplacePairCollection }
+{ TReplacePairs }
+
+procedure TReplacePairs.Assign(Source: TPersistent);
+begin
+  if not (Source is TReplacePairs) then
+    inherited
+  else
+    FPairs.Assign((Source as TReplacePairs).FPairs);
+end;
 
-function TReplacePairCollection.ExecuteReplace(TargetStr: String): String;
+constructor TReplacePairs.Create(AOwner: TComponent);
+begin
+  inherited;
+  FPairs := TReplacePairCollection.Create(TReplacePair);
+end;
+
+destructor TReplacePairs.Destroy;
+begin
+  FPairs.Free;
+  inherited;
+end;
+
+function TReplacePairs.ExecuteReplace(TargetStr: String): String;
 var
   i: integer;
 begin
   Result := TargetStr;
   for i := 0 to Count-1 do
   begin
-    Result := (Items[i] as TReplacePair).ExecuteReplace(Result);
+    Result := Pair[i].ExecuteReplace(Result);
   end;
 end;
 
+function TReplacePairs.GetCount: Integer;
+begin
+  Result := FPairs.Count;
+end;
+
+function TReplacePairs.GetPair(Index: Integer): TReplacePair;
+begin
+  Result := FPairs.Items[Index] as TReplacePair; 
+end;
+
+procedure TReplacePairs.SetPair(Index: Integer; const Value: TReplacePair);
+begin
+  FPairs.Items[Index].Assign(Value);
+end;
+
+procedure TReplacePairs.SetPairs(const Value: TReplacePairCollection);
+begin
+  FPairs.Assign(Value);
+end;
+
 initialization
 
 Classes.RegisterClass(TReplacePresets);
index e48e02f..40f6233 100644 (file)
@@ -14,11 +14,11 @@ type
     procedure btnCancelClick(Sender: TObject);
     procedure btnOkClick(Sender: TObject);
   private
-    function GetPairRec: TReplacePairRec;
-    procedure SetPairRec(const Value: TReplacePairRec);
+    function GetPair: TReplacePair;
+    procedure SetPair(const Value: TReplacePair);
     { Private \90é\8c¾ }
   public
-    property PairRec: TReplacePairRec read GetPairRec write SetPairRec;
+    property Pair: TReplacePair read GetPair write SetPair;
     function Execute: boolean;
   end;
 
@@ -36,11 +36,9 @@ end;
 
 procedure TfrmStrReplaceDialog.btnOkClick(Sender: TObject);
 var
-  PairRec: TReplacePairRec;
   Dummy: String;
 begin
-  PairRec := frmStrReplaceFrame.PairRec;
-  with PairRec do
+  with Pair do
   begin
     if UseRegExp and
       (SafeAndCheckRegExpSubst(BeforeStr, AfterStr, [rfReplaceAll], Dummy) <> '') then
@@ -62,14 +60,14 @@ begin
   Result := ShowModal = mrOk;
 end;
 
-function TfrmStrReplaceDialog.GetPairRec: TReplacePairRec;
+function TfrmStrReplaceDialog.GetPair: TReplacePair;
 begin
-  Result := frmStrReplaceFrame.PairRec;
+  Result := frmStrReplaceFrame.Pair;
 end;
 
-procedure TfrmStrReplaceDialog.SetPairRec(const Value: TReplacePairRec);
+procedure TfrmStrReplaceDialog.SetPair(const Value: TReplacePair);
 begin
-  frmStrReplaceFrame.PairRec := Value;
+  frmStrReplaceFrame.Pair := Value;
 end;
 
 end.
index f097c0f..cd9928a 100644 (file)
@@ -15,13 +15,15 @@ type
     cbxUseRegExp: TCheckBox;
     cbxDontIgnoreCase: TCheckBox;
   private
-    FPairRec: TReplacePairRec;
-    procedure SetPairRec(const Value: TReplacePairRec);
+    FPair: TReplacePair;
+    constructor Create(AOwner: TComponent); override;
+    destructor Destroy; override;
+    procedure SetPairRec(const Value: TReplacePair);
     procedure UpdateControls;
     procedure ControlsToData;
-    function GetPairRec: TReplacePairRec;
+    function GetPairRec: TReplacePair;
   public
-    property PairRec: TReplacePairRec read GetPairRec write SetPairRec;
+    property Pair: TReplacePair read GetPairRec write SetPairRec;
   end;
 
 implementation
@@ -32,7 +34,7 @@ implementation
 
 procedure TfrmStrReplaceFrame.ControlsToData;
 begin
-  with FPairRec do
+  with FPair do
   begin
     BeforeStr  := edtOldPattern.Text;
     AfterStr   := edtNewPattern.Text;
@@ -41,21 +43,33 @@ begin
   end;
 end;
 
-function TfrmStrReplaceFrame.GetPairRec: TReplacePairRec;
+constructor TfrmStrReplaceFrame.Create(AOwner: TComponent);
+begin
+  inherited;
+  FPair := TReplacePair.Create(nil);
+end;
+
+destructor TfrmStrReplaceFrame.Destroy;
+begin
+  FPair.Free;
+  inherited;
+end;
+
+function TfrmStrReplaceFrame.GetPairRec: TReplacePair;
 begin
   ControlsToData;
-  Result := FPairRec;
+  Result := FPair;
 end;
 
-procedure TfrmStrReplaceFrame.SetPairRec(const Value: TReplacePairRec);
+procedure TfrmStrReplaceFrame.SetPairRec(const Value: TReplacePair);
 begin
-  FPairRec := Value;
+  FPair.Assign(Value);
   UpdateControls;
 end;
 
 procedure TfrmStrReplaceFrame.UpdateControls;
 begin
-  with FPairRec do
+  with FPair do
   begin
     edtOldPattern.Text := BeforeStr;
     edtNewPattern.Text := AfterStr;