-
Notifications
You must be signed in to change notification settings - Fork 1
/
ReplaceFrame.pas
95 lines (79 loc) · 2.07 KB
/
ReplaceFrame.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
unit ReplaceFrame;
{$I Information.inc}
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons;
type
TReplaceFrame = class(TFrame)
edSearch: TEdit;
edReplace: TEdit;
cbRegEx: TCheckBox;
cbActive: TCheckBox;
sbTest: TSpeedButton;
sbAdd: TSpeedButton;
sbDel: TSpeedButton;
lbSearch: TLabel;
lbReplace: TLabel;
procedure FrameResize(Sender: TObject);
procedure sbTestClick(Sender: TObject);
procedure sbAddClick(Sender: TObject);
procedure sbDelClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
class var FrameCount: Integer;
end;
implementation
uses
// Delphi
System.StrUtils, System.RegularExpressions,
// CA
CAResources, Utils;
{$R *.dfm}
{ TReplaceFrame }
procedure TReplaceFrame.FrameResize(Sender: TObject);
var
D,I: Integer;
begin
D := lbSearch.Left;
I := (cbRegEx.Left - lbSearch.Width - lbReplace.Width - 5 * D) div 2;
edSearch.Left := 2 * D + lbSearch.Width;
edSearch.Width := I;
lbReplace.Left := edSearch.Left + edSearch.Width + D;
edReplace.Left := lbReplace.Left + lbReplace.Width + D;
edReplace.Width := I;
end;
procedure TReplaceFrame.sbAddClick(Sender: TObject);
begin
with TReplaceFrame.Create(Owner) do
begin
Inc(FrameCount);
Name := 'ReplaceFrame' + IntToStr(FrameCount);
Top := 10000;
Parent := Self.Parent;
end;
end;
procedure TReplaceFrame.sbDelClick(Sender: TObject);
begin
if Parent.ControlCount > 1 then
Free;
end;
procedure TReplaceFrame.sbTestClick(Sender: TObject);
var
S: string;
R: TRegEx;
begin
S := '';
if InputQuery(RsInput, RsFileName, S) then
begin
if cbRegEx.Checked then
begin
R.Create(edSearch.Text);
InfMsg(R.Replace(S, edReplace.Text));
end else
InfMsg(StringReplace(S, edSearch.Text, edReplace.Text, [rfReplaceAll]));
end;
end;
end.