Subject Re: [IBO] clearing comboBox in grid does not produce NULL
Author Helen Borrie
At 03:13 AM 2/04/2003 +0000, you wrote:
>Hi there,
>
>I have a problem, but I'm not sure if I'm missing something.
>
>I have a master-detail form, with a lookupCombo tied to one of the
>fields in the detail (using TIB_Grid)
>This field is STK_ID.
>
>I also have a before update trigger for the detail table, which
>checks the value of STK_ID and performs various actions accordingly.
>
>In the trigger, I have the code:
>IF (new.STK_ID <> old.STK_ID) THEN
>BEGIN
> ...
>END.
>
>Now, if I change the value in the STK_ID combo, the trigger is
>correctly fired. BUT if I clear the value in the combo (by hitting
>DEL), the trigger is not fired.
>
>I want the combobox to clear, and therefore set a value of NULL to
>the underlying field, but this does not appear to be happening.
>
>Is this a known problem, that when DEL is pressed on a lookup combo,
>it is NOT setting the field to NULL?

It's "known" but not a "problem". It is the way null behaves "null is a
state, not a value". The lookup dataset has to have a unique key and, of
course, NULL cannot be a unique key, since it is not a value. i.e. a null
lookup key will NOT keylink to a null polling key, since null=null always
evaluates to False.

If you need to enable the use of the lookup-keysource relationship to set
the polling key to null, then you need to include a non-null dummy key in
the lookup set that will map to a non-null value (a dummy representing
"null") in the polling column. Then, in your Before Insert and Before
Update triggers, you detect this dummy value and set the column to
null. For an integer key, I usually use -1; for a character key, I use
'*'...but it can be whatever you need it to be.

Helen