+#KA$TMyBooleanComponent

© 1998 Darren J. Dwyer, all rights reserved!

This is a test component written to demonstrate the following concepts of BCB :-
•	installing a component
•	creating a property editor
•	creating a component editor
•	creating custom component help
•	creating a custom component icon

TMyBooleanComponent is derived from TDBComboBox. It adds the ability to remember new values entered into a field using a small text file - a short list. The main properties and events added to TDBComboBox by TMyBooleanComponent are:
Properties
ListDefaults A comma delimited list of values which are always in the short list.
ListName The name of the short list text file on disk.

Events
OnAddNew…called whenever a new item is being added to the list.
OnDelete…called to delete an item from the list.
OnSelect…called whenever a selection is made from the list.

+#KA$Notes:
For some reason Microsoft Word 97 was not able to produce a valid RTF file. 
Lotus WordPro 97 was used instead.

+#KA$ListDefaults

A comma delimited list of default values. In the event that the short list file is not found, the default values would be available. This might be handy, for example, the first time the program is used.

As an example: If you have a form with a field for a CPU name, the basic Intel x86 family of CPUs would generally be handy. In this case, you would set ListDefaults to:

"i86", "i186", "i286", "i386", "i486", 
"Pentium", "Pentium Pro"

Note that this is a single line of comma delimited ASCII text. The double-quote characters are needed for the "Pentium Pro" item because it contains an embedded space. They're optional for the other items.

Another example: For a short list of colors, it would be possible to use:

Red, Yellow, Blue

+#KA$ListName

The name of the short list file. For a list of common CPU's, you would set ListName to:

cpu.lst

or something of that sort. The list of all CPU references typed into that list would then be stored in a simple text file of that name, one reference per line of text. 

If you specify a path, the path must exist. Otherwise, C++ Builder will use the current default drive and directory at the time the component is created.

+#KA$OnAddNew

typedef __fastcall void (__closure *TUpdateEvent)
( TObject *Sender, Boolean DblClick, AnsiString Text );

__property TUpdateEvent OnAddNew

On exit from the combo box, TMyBooleanComponent checks to see if the value in the field has changed. If it has changed, the list is checked to see if the value is there. If the field value is not in the list, the OnAddNew event is called. 

If there is no OnAddNew event handler specified, a default handler prompts the operator to confirm adding of the new value.

Otherwise, the specified handler is called. Your event handler can prompt the operator to determine if the new value should be added to the list, or you can just add the value without prompting - or do anything else you want to do…

Text is the field value to add to the list.

In some cases, the operator may want to manually add a few items to the list, so TMyBooleanComponent will detect a double click on the field and check the field value against the list contents, as above. This component is a stripped down version of an original component which indicated to the OnAddNew event handler that the double click event resulted in the OnAddNew event call. However, for this example that code was removed to save space in the listings, so the DblClick flag is not used.

+#KA$OnDelete

typedef __fastcall void (__closure *TUpdateEvent)
( TObject *Sender, Boolean DblClick, AnsiString Text );

__property TUpdateEvent OnDelete

In some cases, the operator may want to delete an item from the list, so TMyBooleanComponent will detect a Double-Click on the field and check the field value against the list contents. If the field value is in the list, the OnDelete event is called.

If there is no OnDelete event handler specified, a default handler prompts the operator to confirm deletion of the field value from the list.

Otherwise, the specified handler is called. Your event handler should prompt the operator to determine if the value should be deleted from the list - or do anything else you want to do…

Text is the field value to delete from the list.

The DblClick parameter is not used for the OnDelete event.

+#KA$OnSelect

enum SelectType_e { 
	ST_Error=-1, ST_None, ST_Delete, 
	ST_CR, ST_Click, ST_Exit };

typedef __fastcall void (__closure *TSelectEvent) 
	( TObject *Sender, SelectType_e EventType, 
	  int ItemsIndex,  AnsiString Text,
	  bool IndexChanged, bool TextChanged );
	
_property TselectEvent OnSelect;

The select event is called in a number of cases to allow other fields on a form to respond to changes in the TMyBooleanComponent field contents. If there is no OnSelect event handler specified, the default procedure is to ignore the event.

SelectType_e EventType

The Select type indicates the manner in which the field value was selected. The possible values are:

ST_CR		The operator typed a value and pressed the Enter key.
ST_Click	The operator clicked on a value in the drop down list.
ST_Exit		The controls OnExit event occurred.

int ItemsIndex

The ItemsIndex parameter is the index into the items list. It is valid only if the value is in the list. 

AnsiString Text

The Text parameter is the value which has been selected.

bool IndexChanged, bool TextChanged

IndexChanged and TextChanged are flags which tell the event handler if either the field value or its index in the list have changed since the OnEnter event occurred.

+#K$Contact

Sam Azer
Email: azer@dsuper.net
http://azer.dsuper.net

The Cobb Group,
C++Builder Developers Journal
http://www.cobb.com/cpb