TDataSetTableProducer's
These automaticaly produce an html table
FormatCell
| Accessing additional fields
| Making a field a link
| Tables with 2 columns
|
FormatCell
The purpose of a TDataSetTableProduce is to simply create
an html table. For each cell of the table, FormatCell is called.
procedure TWebModule1.DataSetTableProducer_ViewFormatCell(Sender: TObject;
CellRow, CellColumn: Integer; var BgColor: THTMLBgColor;
var Align: THTMLAlign; var VAlign: THTMLVAlign; var CustomAttrs,
CellData: String);
- Use CellRow to keep from modifying the first (CellRow=0) row
- Use CellColumn to determine which field is being formatted (the first column is 0)
- CellData is the data from the table, modify this as appropriate
The html string will look something like this
ie, you can modify CustomAttrs and CellData to produce any
html string you want that has that format.
Accessing additional fields
The table producer creates an html table with only those fields/columns
that were specified in the table designer.
However, sometimes additional fields,
(those not explicitly displayed)
are used to help format the data.
Each time FormatCell is called,
all the fields in the current record are available via
str := Table_or_Query_Object.FieldByName('field_name').AsString;
For instance,
one of my lookup tables contains html css class definitions that are used to
display values in different colors. The query merges the data file with
the lookup table, thus providing access to the html code.
By setting the CustomAttrs to these strings, the data is appropriately colored.
For example, the following code
procedure TWebModule1.DataSetTableProducer_ViewFormatCell(Sender: TObject;
CellRow, CellColumn: Integer; var BgColor: THTMLBgColor;
var Align: THTMLAlign; var VAlign: THTMLVAlign; var CustomAttrs,
CellData: String);
begin
// This color codes the third column
if (CellColumn=2) and (CellRow>0) then begin
CustomAttrs := A_DataModule.IBQuery_xyz.FieldByName('html_class').AsString;
end;
end;
is used to to produce table columns like these.
This is a portion of the actual style definition - created automatically
from the lookup tables (never hard code stuff like this).
Making a field a link
This example uses the CellData to create a link to another page.
The target causes the pages to open in another window.
if (CellColumn=0) and (CellRow>0) then begin
CustomAttrs := '>
This is the resulting html.
This example actually produces code that calls a subroutine.
if (CellColumn=0) and (CellRow>0) then begin
CustomAttrs := '>
This is the resulting html.
This is the script - I prefer it in this case because the resulting window looks
more like a dialog box than a web browser.
Tables with 2 columns
The TDataSetTableProducer component generates an html table
with only one column. This is one method to produce tables with 2 columns.
Basically, I create a table with one column in a PageProducer.
When the HTML-transparent tag #Table_2_Columns is processed, I call a DataSetTableProducer.
procedure TWebModule1.PageProducer_xyzHTMLTag(Sender: TObject;
Tag: TTag; const TagString: String; TagParams: TStrings;
var ReplaceText: String);
var
s : string;
begin
if TagString='Table_2_Columns' then begin
s := DataSetTableProducer_Status_2_Columns.Content ;
end;
ReplaceText := s ;
end;
The Table Producer calls FormatCell for each field.
After half of the rows are processed,
this code ends the first table and starts the second table.
procedure TWebModule1.DataSetTableProducer_ViewFormatCell(Sender: TObject;
CellRow, CellColumn: Integer; var BgColor: THTMLBgColor;
var Align: THTMLAlign; var VAlign: THTMLVAlign; var CustomAttrs,
CellData: String);
begin
// This places the second 16 ports in a second column
if (CellRow=16) and (CellColumn=3) then begin
CustomAttrs := CustomAttrs + '>' + CellData + '' + CRLF_mc +
' | ' + // this controls the width betweeen the columns
'' + CRLF_mc +
'Port | Assigned To | Status | Port Configuration |
In this example
- There 16 rows in each column.
- There are 4 fields displayed per row (numbered 0 thru 3).
- CRLF_mc produces a line feed so that the final html is easier to read.
- Notice the the final html tag in CustomAttrs does NOT have its final closing bracket.
The component automatically adds that.
- The table header for the second column is hard coded - Don't write this by hand,
generate the web page, view source, and copy the table header that Delphi generates.
- Since the original CellData is imbedded in CustomAttrs,
CellData is returned as a null string.
Author: Robert Clemenzi -
clemenzi@cpcug.org
|