-
Notifications
You must be signed in to change notification settings - Fork 2
/
Search And Replace Form.pas
152 lines (115 loc) · 4.04 KB
/
Search And Replace Form.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{
Run on the file you want to do the replacement in. You will be asked for stuff.
}
unit ReplaceFormEverywhere;
uses praUtil;
var
StrReplace: string;
fileToDo, formSearch, formReplace: IInterface;
replaceMap: TStringList;
replaceMapVals: TStringList;
// Called before processing
// You can remove it if script doesn't require initialization code
function Initialize: integer;
var
list: TStringList;
curLine: String;
i, j: Integer;
endPos: Integer;
key: String;
val: String;
spacePos: Integer;
begin
Result := 0;
replaceMap := TStringList.create;
replaceMapVals := TStringList.create;
end;
// called for every record selected in xEdit
function Process(e: IInterface): integer;
begin
Result := 0;
fileToDo := GetFile(e);
end;
procedure replaceFormIn(container, search, repl: IInterface);
var
i: integer;
child, lt: IInterface;
begin
lt := LinksTo(container);
if(assigned(lt)) then begin
if(IsSameForm(lt, search)) then begin
AddMessage('Replacing in:');
AddMessage(' '+FullPath(container));
setLinksTo(container, repl);
end;
end;
for i := 0 to ElementCount(container)-1 do begin
child := ElementByIndex(container, i);
// AddMessage(prefix+DisplayName(child)+'='+GetEditValue(child));
replaceFormIn(child, search, repl);
end;
end;
// Called after processing
// You can remove it if script doesn't require finalization code
function Finalize: integer;
var
i, j, numRefs: cardinal;
curRef, formSearch: IInterface;
searchEdid, replaceEdid: string;
frm: TForm;
inputSearch, inputReplace: TEdit;
btnOk, btnCancel: TButton;
resultCode: cardinal;
begin
Result := 0;
if(not assigned(fileToDo)) then begin
exit;
end;
frm := CreateDialog('Search and replace form', 400, 180);
CreateLabel(frm, 10, 2, 'Input Editor or Form IDs to search and replace forms');
CreateLabel(frm, 10, 18, 'Selected file: '+GetFileName(fileToDo));
CreateLabel(frm, 10, 50, 'Search');
inputSearch := CreateInput(frm, 80, 47, '');
inputSearch.width := 250;
CreateLabel(frm, 10, 75, 'Replace with');
inputReplace := CreateInput(frm, 80, 72, '');
inputReplace.width := 250;
btnOk := CreateButton(frm, 50, 120, 'OK');
btnOk.ModalResult := mrYes;
btnOk.Default := true;
btnOk.width := 90;
btnCancel := CreateButton(frm, 250, 120, 'Cancel');
btnCancel.ModalResult := mrCancel;
btnCancel.width := 90;
resultCode := frm.ShowModal;
if(resultCode <> mrYes) then begin
AddMessage('Cancelled');
exit;
end;
searchEdid := trim(inputSearch.text);
replaceEdid :=trim(inputReplace.text);
if(searchEdid = '') or (replaceEdid = '') then begin
AddMessage('Both fields must be filled out');
exit;
end;
formSearch := findFormByString(searchEdid);
if(not assigned(formSearch)) then begin
AddMessage('Could not find '+searchEdid);
exit;
end;
formReplace := findFormByString(replaceEdid);
if(not assigned(formReplace)) then begin
AddMessage('Could not find '+replaceEdid);
exit;
end;
for i := ReferencedByCount(formSearch)-1 downto 0 do begin
curRef := ReferencedByIndex(formSearch, i);
if(GetFileName(GetFile(curRef)) = GetFileName(fileToDo)) then begin
//dumpElem(curRef);
replaceFormIn(curRef, formSearch, formReplace);
end;
end;
{
}
end;
end.