Create a table using the data sensitive WPTableProducer

Top  Previous  Next

The component WPTableProdcer makes it easy to create a table in the TWPRichText word processing component. There is also a data sensitive version called WPTableProdcerDB. It contains a collection "DataSourceLinks" which is used to  establish connections to TDataSource instances.


The table is defined by one or multiple entries in the collection "Blocks". Each of the blocks quote the name of one datasourcelink to build up the reference.


Why did we not link a text-block to a DataSource directly?

a) This abstraction through "links" makes it possible to save and load table definitions without implementation dependent information, such as the real name of the TDataSource component but using an alias name.

b) The DataSourceLink can also create a TDataSource on demand - i.e. when the data of a Query is displayed which is only created when needed.

c) The DataSourceLink contains also display name and description to be used in a GUI.


Each of the blocks also contains a collection of column descriptions to create one or more rows of data.


It is also possible that a block directs to a sub data by telling its name in the property ClientName. The client block has to mention the fieldname which is using select the sub data in its property MasterIDField.


This is an example of a simple master-client table description defined on a form in the Delphi IDE:





object WPTableProducerDB1: TWPTableProducerDB

 ActiveTemplate = 'Orders'   This is the name of the main table block - the first which should be used.

 EditBox = WPRichText1       The attached editor - here the table is created

 Blocks = <                 In "Blocks" the table is described


     Name = 'Orders'         The description for the master rows

     ClientName = 'Items'   With ClientName a link to the sub rows is esstablished

     Columns = <             Here the columns are described.


         Name = 'CUSTOMER_ADR'       This is the name of this column

         Title = 'CUSTOMER_ADR'       The title will be displayed in the header

         WidthPC = 0                 This is the initial width in percent of the total width

         Options = []

         UIOptions = []

         AllowChar = wpallowAuto     The data which can be entered in this cell can be checked.

         RowBreak = False             If this property is true, a new row will be started.

         UpdateField = False         If the data is beeing changed the text can be written to the DB

         FieldName = 'CUSTOMER_ADR'   This is the name of the data base field to be shown.



         Name = 'ORDER_DATE'

         Title = 'ORDER_DATE'

         WidthPC = 0

         Options = []

         UIOptions = []

         AllowChar = wpallowAuto

         RowBreak = False            

         UpdateField = False

         FieldName = 'ORDER_DATE'


     Mode = wpBlockIsTableTemplate

     UpdateDataSourceLinkCursor = False

     DataSourceName = 'DSOrders'   This is the name of the data source link



     Name = 'Items'



 DisableEnableControls = False     When creating the table the DataSet DsiableControl method will be called.

 DataSourceLinks = <


     Name = 'DSOrders'             This is a link to a TDataSource

     DisplayName = 'Orders'

     DisplayDescription = 'Orders'

     UIDFieldName = 'UID'         This is the name of the field which is used to identify each row.

     DataSource = DSOrders

     DynamicDataSource = False



     Name = 'DSOrderItems'

     DisplayName = 'Order Items'

     DisplayDescription = 'Order Items'

     UIDFieldName = 'UID'

     DataSource = DSOrderItems

     DynamicDataSource = False


 Left = 104

 Top = 96




Instead of assigning a datasource event to a DataSourceLink it is also possible to create a query on demand. To so set the property DynamicDataSource = True  and add event handlers to the events OnPrepare and OnUnprepare. In OnPrepare the new data source is assigned to the var parameter TempDataSource. In OnUnprepare TempDataSource is set to nil, otherwise it will be freed automatically by the calling process.


procedure TWPOrderBrowser.WPTableProducerDB1DataSourceLinks2Prepare(...);


TempDataSource := DSQueryProducts;

 QueryProducts.SQL.Text :=

  'SELECT * FROM PRODUCTS WHERE UID=' + WPDataModule.tblOrderItemsPRODUCT_ID.AsString;




procedure TWPOrderBrowser.WPTableProducerDB1DataSourceLinks2UnPrepare(...);



  TempDataSource := nil; // do not free!