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Ä
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
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;
constructor TReplacePreset.Create(Collection: TCollection);
begin
inherited;
- FPairs := TReplacePairCollection.Create(TReplacePair);
+ FPairs := TReplacePairs.Create(nil);
end;
destructor TReplacePreset.Destroy;
inherited;
end;
-procedure TReplacePreset.SetPairs(const Value: TReplacePairCollection);
+procedure TReplacePreset.SetPairs(const Value: TReplacePairs);
begin
FPairs.Assign(Value);
end;
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);
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;
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
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.
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
procedure TfrmStrReplaceFrame.ControlsToData;
begin
- with FPairRec do
+ with FPair do
begin
BeforeStr := edtOldPattern.Text;
AfterStr := edtNewPattern.Text;
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;