diff --git a/.gitattributes b/.gitattributes
index b08f46b73e..4130fceb2d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -117,6 +117,7 @@ components/codetools/examples/scanexamples/identcomplexample.pas svneol=native#t
components/codetools/examples/scanexamples/missingh2pasdirectives.pas svneol=native#text/plain
components/codetools/examples/scanexamples/modemacpas.pas svneol=native#text/plain
components/codetools/examples/scanexamples/overloadedfunction.pas svneol=native#text/plain
+components/codetools/examples/scanexamples/resourcetest1.pas svneol=native#text/plain
components/codetools/examples/scanexamples/simpleunit1.pas svneol=native#text/plain
components/codetools/examples/scanexamples/tgeneric2.pas svneol=native#text/plain
components/codetools/examples/scanexamples/uglyifdefs.pas svneol=native#text/plain
diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas
index a74d7f5fdd..3562d65d9c 100644
--- a/components/codetools/codetoolmanager.pas
+++ b/components/codetools/codetoolmanager.pas
@@ -322,7 +322,7 @@ type
out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer;
const Filename: string = ''; SearchInCleanSrc: boolean = true): boolean;
function AddResourceDirective(Code: TCodeBuffer; const Filename: string;
- SearchInCleanSrc: boolean = true): boolean;
+ SearchInCleanSrc: boolean = true; const NewSrc: string = ''): boolean;
function FixIncludeFilenames(Code: TCodeBuffer; Recursive: boolean;
out MissingIncludeFilesCodeXYPos: TFPList): boolean;
function FixMissingH2PasDirectives(Code: TCodeBuffer;
@@ -2406,7 +2406,8 @@ begin
end;
function TCodeToolManager.AddResourceDirective(Code: TCodeBuffer;
- const Filename: string; SearchInCleanSrc: boolean): boolean;
+ const Filename: string; SearchInCleanSrc: boolean; const NewSrc: string
+ ): boolean;
var
Tree: TCompilerDirectivesTree;
Node: TCodeTreeNode;
@@ -2418,7 +2419,7 @@ begin
if SearchInCleanSrc then begin
if not InitCurCodeTool(Code) then exit;
try
- Result:=FCurCodeTool.AddResourceDirective(Filename,SourceChangeCache);
+ Result:=FCurCodeTool.AddResourceDirective(Filename,SourceChangeCache,NewSrc);
except
on e: Exception do Result:=HandleException(e);
end;
@@ -2429,7 +2430,7 @@ begin
Tree.Parse(Code,GetNestedCommentsFlagForFile(Code.Filename));
Node:=Tree.FindResourceDirective(Filename);
if Node=nil then
- Result:=AddResourceDirective(Code,Filename,true)
+ Result:=AddResourceDirective(Code,Filename,true,NewSrc)
else
Result:=true;
finally
diff --git a/components/codetools/examples/replaceresourcedirectives.lpi b/components/codetools/examples/replaceresourcedirectives.lpi
index 2e358f18ae..e0213b5def 100644
--- a/components/codetools/examples/replaceresourcedirectives.lpi
+++ b/components/codetools/examples/replaceresourcedirectives.lpi
@@ -27,10 +27,10 @@
-
+
-
+
diff --git a/components/codetools/examples/replaceresourcedirectives.lpr b/components/codetools/examples/replaceresourcedirectives.lpr
index 109e59da19..2a54fba0db 100644
--- a/components/codetools/examples/replaceresourcedirectives.lpr
+++ b/components/codetools/examples/replaceresourcedirectives.lpr
@@ -37,7 +37,6 @@ var
NewCode: TCodeBuffer;
NewX, NewY, NewTopLine: integer;
begin
- aResY
// load the file
if ParamCount>=1 then
Filename:=ExpandFileName(ParamStr(1))
@@ -47,7 +46,9 @@ begin
if Code=nil then
raise Exception.Create('loading failed '+Filename);
- if not CodeToolBoss.AddResourceDirective(Code,'*.res',false) then begin
+ if not CodeToolBoss.AddResourceDirective(Code,'*.res',false,
+ '{$IFDEF SomePlatform}{$R *.res}{$ENDIF}')
+ then begin
writeln('FAILED: unable to add resource');
if CodeToolBoss.ErrorMessage<>'' then
writeln('CodeToolBoss.ErrorMessage=',CodeToolBoss.ErrorMessage);
diff --git a/components/codetools/examples/scanexamples/resourcetest1.pas b/components/codetools/examples/scanexamples/resourcetest1.pas
new file mode 100644
index 0000000000..bbe6dea82d
--- /dev/null
+++ b/components/codetools/examples/scanexamples/resourcetest1.pas
@@ -0,0 +1,15 @@
+program resourcetest1;
+
+{$mode objfpc}{$H+}
+
+uses
+ Classes, SysUtils;
+
+{$IFDEF Windows}
+{$R *.res}
+{$ENDIF}
+
+begin
+
+end.
+
diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas
index 43e5cb5012..3b775d287c 100644
--- a/components/codetools/stdcodetools.pas
+++ b/components/codetools/stdcodetools.pas
@@ -217,7 +217,8 @@ type
var NewPos: TCodeXYPosition; var NewTopLine: integer;
const Filename: string = ''): boolean;
function AddResourceDirective(const Filename: string;
- SourceChangeCache: TSourceChangeCache): boolean;
+ SourceChangeCache: TSourceChangeCache; const NewSrc: string = ''
+ ): boolean;
function FixIncludeFilenames(Code: TCodeBuffer;
SourceChangeCache: TSourceChangeCache;
out FoundIncludeFiles: TStrings;
@@ -4711,11 +4712,12 @@ begin
end;
function TStandardCodeTool.AddResourceDirective(const Filename: string;
- SourceChangeCache: TSourceChangeCache): boolean;
+ SourceChangeCache: TSourceChangeCache; const NewSrc: string): boolean;
var
ANode: TCodeTreeNode;
Indent: LongInt;
InsertPos: Integer;
+ AddSrc: String;
begin
Result:=false;
BuildTree(true);
@@ -4743,8 +4745,12 @@ begin
// insert directive
SourceChangeCache.MainScanner:=Scanner;
+ if NewSrc<>'' then
+ AddSrc:=NewSrc
+ else
+ AddSrc:=GetIndentStr(Indent)+'{$R '+Filename+'}';
if not SourceChangeCache.Replace(gtEmptyLine,gtEmptyLine,InsertPos,InsertPos,
- GetIndentStr(Indent)+'{$R '+Filename+'}') then exit;
+ AddSrc) then exit;
if not SourceChangeCache.Apply then exit;
Result:=true;