Subject Re: [IBO] Help with Descending from TIB_CustomCombo
Author Paul Vinkenoog
Hi Mark,

> I'm wanting to create my own Lookup combo that simply changes some
> behaviour in the KeyPress method.

> I've created a new component descending from TIB_CustomCombo, just
> as TIB_LookupCombo does. eg.
> TIB_LookupComboB = class(TIB_CustomCombo)
> As a simple test, I copied and pasted the listing for
> TIB_LookupCombo. After adding in the two defines:
> {$DEFINE IBG_CustomGrid}
> {$DEFINE IBG_LookupCombo}
> The component compiles.

When you say "listing", do you mean the entire interface and
implementation for TIB_LookupCombo and TIB_LookupComboLink? (But with
different names for both.)

> HOWEVER...if I override the KeyPress method and simple re-implement
> (copy/paste from TIB_LookupCombo) an identical method, I get about
> 27 errors! All of the errors seem to be relating to undefined
> properties, such as DataLink (from PopupList.DataLink) and BDataset
> (I'm guessing it too is from the PopupList).

"DataLink" is a TIB_LookupComboLink. Maybe you haven't copied all the
logic correctly. Or - in the case you didn't copy the interface from
TIB_LookupCombo - maybe you haven't published the necessary properties.

I can't tell exactly what happens here, but as a general advice: if
you want to mimic another component almost exactly and only change a
couple of things, don't descend from that component's ancestor, but
from the component itself, and override the methods you want to
implement differently:


TIB_LookupComboB = class( TIB_LookupCombo )
procedure KeyPress(var Key: Char); override;



procedure TIB_CustomCombo.KeyPress( var Key: Char);

An additional benefit of this approach (apart from saving you
headaches) is that you can now use a TIB_LookupComboB anyplace a
TIB_LookupCombo is expected.

Like they said in the Borland manuals long ago: Don't reinvent the
wheel - inherit it!

Paul Vinkenoog