hcOPF LookupLists

A common problem that developers have to deal with is validation of input against a lookup table in the database.  Sometimes the “table” isn’t even in the database so a hard coded list of key/value pairs is used instead.  In each case, hcOPF provides a solution to eliminate all the boiler plate code you might use to populate a TComboBox or similar control with such values.

Static Values

If the Key/Value pairs are small in number and static then an array of ThcKeyValue pairs can be declared as such:

MaritalStatusKV :array[1..2] of ThcKeyValuePair = (('S','Single'),('M','Married'));

Then simply use the ThcComboBoxKVMediator in the binding for the TComboBox that displays the MaritalStatus on the form and in the FormCreate event, use the following class method call to populate the control:


In the Database

If the Key/Value pairs you need to use reside in the database, its just as easy.  In a TDatamodule, drop on a ThcLookupList component.  Enter a SQL select statement that would give you the result set you want, and then enter the KeyField and ValueField.  In the form where you need to validate input, use a ThcTComboBoxLookupListMediator.  Choose the LookupList you dropped on the datamodule, the control and the attribute and you’re done.  The control will automatically be populated when the form is streamed in. Remember to choose the ForeignKey attribute for the attribute to bind since hcOPF automatically populates key information prior to saving objects.

The cool thing about this component is that it dynamically creates MetaData from the select statement you enter.  All the columns in the select statement are added to the ThcObjects used to populate the TStringList.Objects, so if you need to use more than a simple Key/Value pair in the object, it’s still a breeze.  For now, if the Key value is Null, the ThcComboBoxLookupListMediator automatically selects the first item in the list.  This may not be the desired behaviour, so a custom mediator may be required.

There still needs to be some design-time work done for this component, but it’s functional and available now in SVN if you want to check it out.  Only D7 projects have been updated with some of the latest changes.  I haven’t checked out how the JEDI deal with syncing multiple projects across Delphi versions yet…

4 Responses to “hcOPF LookupLists”

  1. Birger Jansen Says:

    A common problem we are facing is Lookuplists that are depending on each other. For example, you have an order form. The order is linked to a company. Optionally, you can fill in a contact person for that order. The contact person list should then only show persons from the selected company. Is that possible in hcOPF?

  2. Paul Bennett Says:

    I have been following this blog re OPF for some time and finally took the plunge and decided to ‘check it out’ for myself.
    I downloaded the latest build from the SVN site, but when I try to install it (either in D7 or D2010) I get the following compiler errors -

    [Fatal Error] HengenOPFCore.dpk(39): Required package ‘JvCore’ not found

    If I change JvCore to JvCoreD7R then I get -
    [Fatal Error] Required package ‘CSP20I70′ not found

    How can I get hcOPF to install correctly??

  3. Larry Hengen Says:


    This is certainly possible. I did so for an O&G company I used to work for in which I used an earlier incarnation of hcOPF. They had a business hierarchy with Business Unit, District, Area, & Prospect levels. If you send me an email as a reminder I will see if I can provide the approach I used (see my About page).

  4. Larry Hengen Says:


    Unfortunately because the framework is still a work in progress, and I haven’t had time to setup a continuous integration server to provide testing and reliable deployment packages, so you can certainly run into such grief.

    In order to use hcOPF you need the latest JVCL from their SVN repo. That will fix the initial error you got (although you’re technique is another way around it).

    CSP20I70 is a CodeSite package. You can remove it as long as you build without the hcCodeSite conditional.

    Otherwise, the only tip I can give you is that the D7 packages are more current than any compiler target since that is what I am using, and you can always email me if you run into issues.

Leave a Reply