1{ 2 *************************************************************************** 3 * * 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. * 8 * * 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. * 13 * * 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. * 18 * * 19 *************************************************************************** 20 21 Author: Mattias Gaertner 22 23 Abstract: 24 Demonstration of how to add or remove resource directives. 25} 26program ReplaceResourceDirectives; 27 28{$mode objfpc}{$H+} 29 30uses 31 SysUtils, CodeCache, CodeToolManager; 32 33var 34 Filename: string; 35 Code: TCodeBuffer; 36 NewCode: TCodeBuffer; 37 NewX, NewY, NewTopLine: integer; 38begin 39 // load the file 40 if ParamCount>=1 then 41 Filename:=ExpandFileName(ParamStr(1)) 42 else 43 Filename:=ExpandFileName(SetDirSeparators('scanexamples/resourcetest1.pas')); 44 Code:=CodeToolBoss.LoadFile(Filename,false,false); 45 if Code=nil then 46 raise Exception.Create('loading failed '+Filename); 47 48 if not CodeToolBoss.AddResourceDirective(Code,'*.res',false, 49 '{$IFDEF SomePlatform}{$R *.res}{$ENDIF}') 50 then begin 51 writeln('FAILED: unable to add resource'); 52 if CodeToolBoss.ErrorMessage<>'' then 53 writeln('CodeToolBoss.ErrorMessage=',CodeToolBoss.ErrorMessage); 54 halt; 55 end; 56 57 if not CodeToolBoss.FindResourceDirective(Code,1,1, 58 NewCode,NewX,NewY,NewTopLine,'',false) then 59 begin 60 writeln('FAILED: did not find any resource directive'); 61 if CodeToolBoss.ErrorMessage<>'' then 62 writeln('CodeToolBoss.ErrorMessage=',CodeToolBoss.ErrorMessage); 63 halt; 64 end; 65 66 // write the new source: 67 writeln('---------BEFORE REMOVE-------------'); 68 writeln(Code.Source); 69 writeln('-----------------------------------'); 70 71 writeln(NewCode.Filename,' X=',NewX,' Y=',NewY); 72 73 if not CodeToolBoss.RemoveDirective(NewCode,NewX,NewY,true) then begin 74 writeln('FAILED to remove resource directive'); 75 if CodeToolBoss.ErrorMessage<>'' then 76 writeln('CodeToolBoss.ErrorMessage=',CodeToolBoss.ErrorMessage); 77 halt; 78 end; 79 80 // write the new source: 81 writeln('---------AFTER REMOVE---------------'); 82 writeln(Code.Source); 83 writeln('-----------------------------------'); 84end. 85 86