Using better resource names
You may find it helpful to name resources with file-like names. Doing this will make it easier to migrate an existing series of interlinked HTML files to resources (providing the files are all in the same directory). Why? because the existing local links in the file will still work after the move!
Windows does it!
Several HTML resources in Windows DLLs are named in this way.
For example, suppose you have an application that displays local files from a single directory in a TWebBrowser control. Assume the directory contains the following files:
Each HTML file displays the logo and so contains an
<img> tag such as:
<img src="logo.gif" ... />
index.html contains a relative link to both
<a href="page1.html">Page 1</a><br />
<a href="page2.html">Page 2</a>
You now decide to store the pages within your program's HTML resources and display them using the
res:// protocol. Suppose you decided to give an arbitrary name to each resource as follows:
INDEX_PAGE 23 "index.html"
PAGE_1 23 "page1.html"
PAGE_2 23 "page2.html"
LOGO_GIF 23 "logo.gif"
To get your program working again you will need to track down every link and change it to reference the new resource name rather than the old file name. For example, each of the logo
<img> tags will have to be changed to:
<img src="LOGO_GIF" ... />
This is obviously prone to error. A far better way would be to name the resources with the same name as the original file, i.e.:
index.html 23 "index.html"
page1.html 23 "page1.html"
page2.html 23 "page2.html"
logo.gif 23 "logo.gif"
Using this scheme all the original links will continue to work unchanged. Of course this technique only works if all the files are in the same directory.
Problems with BRCC32
There's always a gotcha somewhere isn't there? The BRCC32 resource compiler that ships with Delphi refuses to compile any resource file that has dots in any of its resource names. This means that the naming scheme proposed above is useless for those of us who use BRCC32.
To get round the above problem I have written HTML resource compiler, a command line application that can compile HTML resource files. This compiler automatically names each resource after its associated file.
I have never used the Microsoft® RC compiler so can't comment on whether or not it will work in this situation. If you know please please open an issue on GitHub (GitHub account required) and let me know so I can update the article.