1. Tech

Your suggestion is on its way!

An email with a link to:

http://delphi.about.com/od/internetintranet/l/aa061901a.htm

was emailed to:

Thanks for sharing About.com with others!

Web Site inside a Delphi EXE
How to store Web-style content inside a Delphi application.
 More of this Feature
• Part 1: Resource Files Made Easy
• Part 2: Inside the EXE (compiling .rc files)
• Part 4: Resource only DLL
• Part 5: StringTable resources
• Part 6: Resource Managers
• Part 7: Fixing the "Duplicate resource" error
 Join the Discussion
"Post your views, comments, questions and doubts to this article."
Discuss!
 Related Resources
• Web programming
 Elsewhere on the Web
• HTML Res: MS overview
• Delphi HTML Resource Tool
• HTML Dialogs in Delphi

This is the third article in the series about storing more than just executable code inside a Delphi application.
In the introductory article we saw how Delphi uses standard Windows resource files like icons, bitmaps and cursors. As explained, resource files that store such kind of data can be created with Delphi's Image Editor. The second article explained how to use sound files, video clips, animations and more generally any kind of binary files in a Delphi executable - we placed a mp3 file inside a Delphi exe. As stated, we use Borland Resource Compiler (BRCC32.exe) to create a resource file that gets linked with an executable file.

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:

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><br> This is a HTML Delphi resource test:<br><br> <img src="/GIF/ABOUTDP" width=106 height=58 border=0 alt=""><br> </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

This should result in:

HTML page from a Delphi resource

That's it. If you have any questions; like how use the HREF tag inside a html resource, or how to display the html page inside a Delphi form; please post them on the Delphi Programming Forum!

©2014 About.com. All rights reserved.