2
***************************************************************************
4
* This source is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This code is distributed in the hope that it will be useful, but *
10
* WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12
* General Public License for more details. *
14
* A copy of the GNU General Public License is available on the World *
15
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
16
* obtain it by writing to the Free Software Foundation, *
17
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************
21
Author: Mattias Gaertner
24
Demonstration how to remove a with block.
31
Classes, SysUtils, CodeCache, CodeToolManager, FileProcs, AVL_Tree, CodeAtom,
32
BasicCodeTools, SourceChanger, CodeTree, FindDeclarationTool, AddWith1;
35
ConfigFilename = 'codetools.config';
46
Filename:='scanexamples/addwith1.pas';
53
if (ParamCount>=1) and (Paramcount<>6) then begin
55
writeln(' ',ParamStr(0));
56
writeln(' ',ParamStr(0),' <filename> <X1> <Y1> <X2> <Y2> <WithExpression>');
57
writeln(' ',ParamStr(0),' ',Filename,' ',X1,' ',Y1,' ',X2,' ',Y2,' ',WithExpr);
60
CodeToolBoss.SimpleInit(ConfigFilename);
63
if Paramcount=6 then begin
64
Filename:=ParamStrUTF8(1);
65
X1:=StrToIntDef(ParamStrUTF8(2),1);
66
Y1:=StrToIntDef(ParamStrUTF8(3),1);
67
X2:=StrToIntDef(ParamStrUTF8(4),1);
68
Y2:=StrToIntDef(ParamStrUTF8(5),1);
69
WithExpr:=ParamStrUTF8(6);
72
Filename:=ExpandFileName(SetDirSeparators(Filename));
73
Code:=CodeToolBoss.LoadFile(Filename,false,false);
75
raise Exception.Create('loading failed: '+Filename);
77
// parse the unit and remove the with variable
78
Candidates:=TStringList.Create;
79
if not CodeToolBoss.AddWithBlock(Code,X1,Y1,X2,Y2,'',Candidates) then
80
raise Exception.Create('Finding candidates for "With" block failed');
82
if not CodeToolBoss.AddWithBlock(Code,X1,Y1,X2,Y2,WithExpr,nil) then
83
raise Exception.Create('Adding "With" block for "'+WithExpr+'" failed');
85
// write the new source:
86
writeln('-----------------------------------');
87
writeln('New source:');
89
writeln('-----------------------------------');