A Delphi CheckList Component

by Jim Karabatsos - GUI Computing

Here is another component that you can use in your Delphi projects. This component creates an owner-draw list box to implement what appears to the user to be a scrolling set of checkboxes, which is a very resource-effective way to deal with a large number of boolean choices.

Here is what the control looks like at at run time:

This control descends from TCustomListBox and publishes most of the protected properties of that class. The exceptions are the ExtendedSelect, MultiSelect and Style properties which are kept Protected and given new default values. Essentially these properties need to be set as shown in the source, so we get the desired behaviour.

We also do not publish the OnDrawItem or OnMeasureItem properties. OnMeasureItem can never be called because we have made the listbox lbOwnerDrawFixed, which means all items are the same height. OnDrawItem is where the user would do their own drawing; seeing as we are handling all of that in the component, it is not needed. Instead, we override the DrawItem procedure of the TCustomListBox to take over the drawing of each item. The drawing is quite straight-forward — basically, we clear the area, draw a square, draw a cross if the item is selected, then print the text. It looks more complex than it is, but if you follow it you’ll figure out what is going on.

As usual, use Options | Install Components to install this component into your system. Enjoy!


Written by: Jim Karabatsos



[HOME] [TABLE OF CONTENTS] [SEARCH]