Delphi WebServers - Using Tags

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.

General | Basic Tags | Persistent data | Radio Buttons | ComboBox | Headers and Footers


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

In the Delphi 5 help, The tag format is defined under TCustomPageProducer.HandleTag.

Basic Tags

Persistent data - Hidden fields

Some applications require state information to be maintained regardless of what is displayed. For that, I use hidden fields. Some applications use cookies for this type of information.

Radio Buttons

In this case, one of the buttons is selected. Mode is a global variable used to control which button to select. 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. 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.

Headers and Footers

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.

Author: Robert Clemenzi -
URL: http:// / user / clemenzi / technical / Databases / Delphi / WebServers / UsingTags.html