Many of you have asked how your application can be a container for any
Web-style content, including HTML resources and pictures that are part of your
project.
This articles will show you how HTML and associated files
(pictures) can easily be included within a Delphi application. As a result, you
simply have to distribute an EXE file that includes HTML pages, as it would do
with icons and cursors.
Creating a HTML page
For the
start we have to assemble a (simple) html page. Use your favorite HTML editor
and create one page with one associated picture. I'll name mine
aboutindex.htm.
Note that when you add a picture tag inside a htm
page it looks something like:
<img src="/library/graphics/adp.gif" ...>
We have to alter the IMG tags so that the SRC attribute equals the name we are to give to a picture in a resource:
<img src="ABOUTDP" ...>
My HTML code looks like:
<HTML><HEAD><TITLE>HTML inside a Delphi
exe</TITLE></HEAD><BODY> This is a HTML Delphi resource test:<br> <img src="/GIF/ABOUTDP" width=106 height=58 border=0 alt=""> </BODY></HTML> |
Creating and compiling a resource
file
Remember that to create a new resource script file, you have
to:
1. Create a new text file in your projects directory.
2. Rename it to
AHTMLDelphi.rc.
3. Write down the following two lines of text in the
AHTMLDelphi.rc file.
DELPHIINDEX HTML
"c:\Delphi\projects\aboutindex.htm" ABOUTDP GIF "c:\library\graphics\adp.gif" |
Note: the resource type "HTML" is RT_HTML, predefined as the resource type "23". This is the default resource type for the RES protocol.
In this way we have prepared one HTML page and one GIF picture to be included in the binary code of our EXE module.
The next step is to compile the .rc file. To compile the AHTMLDelphi.rc file to a .res file execute this command at the command prompt (in the projects directory):
BRCC32 AHTMLDelphi.RC
The final step is to add the following compiler directive to a unit in your project. RES file must be included in the program's build by adding a line like this:
{$R AHTMLDelphi.RES} |
Displaying inside a Web
browser
When you have the application's exe (let's call it:
myhtmldelphi.exe) the HTML resource contained within can be accessed via the
RES: protocol. Run Internet Explorer and, in the Address bar, type the
following:
res://c:\myhtmldelphi.exe/RT_HTML/DELPHIINDEX