Delphi 2007 and Infopower Studio 2007

Since the mid 1990′s, one of my favorite third party component suites for Delphi has been Woll2Woll‘s Infopower data aware controls suite.

In particular, I rely heavily upon the TwwDBGrid which adds a number of very nice functionalities to the native Delphi TDBGrid, including:

  • ability to embedd other Infopower or 1st Class data aware controls such as drop down or dialog popup controls which may link to a lookup table or just have hard coded values.
  • OnCalcCellColours event which allows easier control over drawing brush colour, font style and colour to cells in the grid
  • allow column titles to act as buttons – I use this to sort the table by adding code to the OnTitleButtonClick event
  • a number of other additional features and events which admittedly I don’t use.

One issue I do have with the use of embedded controls in their grid is presumably a bug which is worth being aware of:

  • a common need is to display a lookup description in the grid instead of the primary key value for the lookup, and allow the user to drop down a combo box or popup a dialog form to select a different lookup description which will then change the underlying integer key value in the dataset
  • let’s look at the usual case where the main dataset has a field “LookupID” of type integer which references “ID” field of a lookup dataset, “TblLookup”
  • in the TwwDBGrid, we can drop a TwwDBLookupCombo component or a TwwDBLookupComboDlg and set its properties Datasource = MainDatasource, DataField = LookupID, LookupTable = TblLookup. I set Use Tfields = false so that your Selected settings do not affect other controls. Click on the Selected property to choose what the user will see – I usually ensure the lookup description field is the first column, unless you have another lookup field the user can search on.
  • at design time, you then double click on the TwwDBGrid to allow setting the properties for each column – for the LookupID column, set ControlType to CustomEdit and choose the component for the ControlName, and if you want the user to see the value of the component text instead of the underlying column value (the integer value), you need to check Control Always Paints.
  • when you run this, all works well (assuming both datasets are active), but you will notice one annoying behaviour – when the user clicks within that cell, the lookup description disappears and the user is shown the underlying integer value which means nothing to the user.
  • my way of getting around this is to add a lookup-type field to the main dataset and use this as the grid column field
  • this works perfectly if you use a TwwDBLookupCombo component
  • unfortunately, if you use a TwwDBLookupComboDlg, it may appear to work perfectly, but if you validate data entry using the  dataset’s TField.OnValidate event and raise an exception for an invalid value, this exception will freeze the grid and the user will have to close the application and re-start it.
  • now one could ask why should you ever get an invalid data entry given that you are supplying the user with a fixed set of values to use via a lookup table, well the short answer is that sometimes these lookup values may not be valid pending other circumstances with values in other fields of that record.
  • thus, unless someone has a solution to this, I would avoid using TwwDBLookupComboDlg within a grid linked to a lookup field of the main dataset, and use TwwDBLookupCombo instead.
No comments yet.

You must be logged in to post a comment.

No trackbacks yet.