Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Sample using ElementsByMIP to find and replace values on records.
- }
- unit userscript;
- uses mteFunctions;
- var
- path, find, replace: string;
- function Initialize: integer;
- begin
- path := InputBox('Path', 'Enter a path to search on:', '');
- find := InputBox('Find', 'Enter a value to search for:', '');
- replace := InputBox('Replace', 'Enter a value to replace found values with:', '');
- AddMessage('Searching "'+path+'". Replacing "'+find+'" with "'+replace+'"');
- end;
- function Process(e: IInterface): integer;
- var
- lst: TList;
- sl: TStringList;
- i: integer;
- val: string;
- element: IInterface;
- begin
- AddMessage('Processing '+Name(e));
- // create lists
- lst := TList.Create;
- sl := TStringList.Create;
- // get elements and values
- ElementsByMIP(lst, e, path);
- mgeev(sl, lst);
- // replace values matching find
- for i := 0 to Pred(sl.Count) do begin
- element := ObjectToElement(lst[i]);
- if Assigned(element) then begin
- AddMessage(' "'+IndexedPath(element)+'" = '+sl[i]);
- if sl[i] = find then begin
- AddMessage(' Replacing value with '+replace);
- SetEditValue(element, replace);
- end;
- end;
- end;
- // free memory
- lst.Free;
- sl.Free;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment