Directive $R Bug and workaround
Posted March 30th, 2009 by Issamin QC may be you can find many reports about Delphi resource files bugs and enhancing requests, and some of them may be about using $R directive in "wrong places", even there are no mention about such "wrong places" in the documentation. this bug QC#72574 also about using $R directive in "wrong place", or let me say "wrong way", even it has some kind of "fun side". 
You will notice this bug in Delphi2006, Delphi2007 and Delphi2009, when using $R directive inside the source file of the Package Projects.
Steps to Reproduce:
- begin new package project and save it.
- create new resource file like (ShowMeBug.res) for example, and save it in the project directory.
- from the project menu select "View Source".
- in the package source file and after the line {$R *.res} enter a new line and type this line {$R ShowMeBug.res} letter by letter and don't use copy/paste.
- save the project.
- close the project.
- reopen the project.
- open the "Project Manager" window, expand the "contains" directory, you will see random parts of the resource file name added to the "contains" like this:
S
Sh
Sho
Show
ShowM
ShowMe
ShowMeB
ShowMeBu
ShowMeBug
ShowMeBug.r
ShowMeBug.re
ShowMeBug.res
the funny thing is the project still can be compiled without any warning message!.
actually the real "mess" is in the "dproj" file not in the "dpk" file, if you open "dproj" file you will see something like this:
<DCCReference Include="ShowMeBug.res"/>
<DCCReference Include="rtl.dcp"/>
<DCCReference Include="ShowMeBug.re"/>
<DCCReference Include="ShowMeBug.r"/>
<DCCReference Include="ShowMeBug"/>
<DCCReference Include="ShowMeBu"/>
<DCCReference Include="ShowMeB"/>
<DCCReference Include="ShowMe"/>
<DCCReference Include="ShowM"/>
<DCCReference Include="Show"/>
<DCCReference Include="Sho"/>
<DCCReference Include="Sh"/>
<DCCReference Include="S"/>
workaround:
well, i don't know if it is correct to name this as a workaround... but it works 
- copy the resource file name and paste it directly after $R doesn't raise this bug!
- using $Resource instead of $R doesn't raise this bug!
- adding the {$R ShowMeBug.res} line after all directives doesn't raise this bug!
is there some kind of "conflict" between $R (resource file) and $R+/- (range check), or it's just an Editor error, i don't know, but I think tell solving this bug, it will be good idea to add a warning message [of using $R in "wrong places"] in the beginning of the source file, or at least add this warning to the documentation, that can help avoiding such kind of bugs.
Regards,
{ Arabic Programmer; }
Recent comments