Typically, you will want to design an html template and let your web server
add a small amount of data.
The locations where the data should go are indicated via tags.
In general, the examples below are from working code (fewer errors that way)
where the data is displayed in a table. As a result, I have simply left in the table
formatting tags.
In all cases, the Delphi code examples are just the code in the common
TWebModule1.xyz_HTMLTag section.
Normally, an application will have one or more PageProducers -
components that generate html. The normal approach is to create
an html template per PageProducer
and place them in either HTMLDoc or HTMLFile.
(I prefer HTMLDoc because everything is compiled into a single file.
HTMLFile allows modifying the templates without recompiling the application.)
These templates are basically just regular html with a few special tags -
the OnHTMLTag event allows your program to replace the tags
with the appropriate html.
Each web server should have a single OnHTMLTag method and
that method should be assigned to the OnHTMLTag
event of all the PageProducers
This method will be called once for each tag in the template
All PageProducers will interpret the tags the same way
It allows one template to include another
In the Delphi 5 help,
The tag format is defined under
TCustomPageProducer.HandleTag.
Some applications require state information to be maintained
regardless of what is displayed. For that, I use hidden fields.
HTML Template
Delphi code
if CompareText(TagString, 'Port_bc') = 0 then begin
ReplaceText := Port_bc;
end;
if CompareText(TagString, 'Filter_bc') = 0 then begin
ReplaceText := Filter_bc;
end;
HTML code
Some applications use cookies for this type of information.
if CompareText(TagString, 'mode') = 0 then begin
// This checks one of the radio buttons
if CompareText(TagParams.Values['n'], Mode) = 0 then
ReplaceText := 'checked' ;
end;
HTML code
Query
Add
Remove
The parameter name is only a single letter - n - just to
make the code easier to read.
This is one of the more complex examples -
the method html_Format_List reads values from a database
and creates an HTML combo box based on the parameters.
HTML Template
User
<#user_list>
Delphi code
if CompareText(TagString, 'user_list') = 0 then begin
Users_DataModule.Group_ID := 'Sph_G';
ReplaceText := Users_DataModule.html_Format_List
(Users_DataModule.IBQuery_Users_View,
'User_ID', 'Name', User, 'User') ;
end;
HTML code
User
I have written a number of methods that produce html based
on a few parameters and a database.
In the generic case, a query is sent to the datamodule before html_Format_List is called.
In other cases, I have predefined queries. In the example above,
setting Group_ID controls which records are returned.
In some applications, the header and footer information are basically
the same for several pages.
I have defined header and footer templates in
PageProducer_Common_Header
and
PageProducer_Common_Footer
respectively.
HTML Template
<#Common_Header>
<#Common_footer>
Delphi code
if CompareText(TagString, 'Common_Header') = 0 then begin
ReplaceText := PageProducer_Common_Header.Content ;
end;
if CompareText(TagString, 'Common_Footer') = 0 then begin
ReplaceText := PageProducer_Common_Footer.Content ;
end;
HTML code
This is quite involved, it contains the html, head, and body tags
as well as any common javascript.
In the case of my portable barcode reader, this also contains
Form start and end tags
Hidden field tags, to keep the same data available on all related pages