Subject Re: [IBO] automatic fill other fields
Author Helen Borrie
At 08:49 AM 14/06/2003 +0000, you wrote:
>how do we automatically fill the other field which correspond to the
>record selected in the TIB_lookupcombo
>
>i have try this
>
>procedure TForm_stocks.IB_LookupCombo1CloseUp(Sender: TObject);
>begin
>parent.fieldbyname('unit').asstring:=lookup.fieldbyname
>('unit2').asstring;
>end;
>
>
>but I think this isn't the solution after all.

No. You don't have to do any code to make the autofill happen. You have
to set the Lookup dataset up properly.

Simple case: the lookup key is displayed and will change (in edit mode) if
user selects a different value from the TIBLookupCombo:

Parent dataset, qParent:
select col1, col2, lookupkey from t_parent
Datasource: dsParent
FieldsVisible: lookupcolumn=True

Lookup dataset, qLookup
select PKey, Description
from Lookup
Keysource: dsParent
KeyLinks: lookup.Pkey=Parent.lookupkey



Slightly less simple case: Subquery expression p_description is displayed
instead of the lookupkey and gets invalidated if user selects (in edit
mode) a different description. Selecting different description updates the
(invisible) lookupkey.

Parent dataset, qParent:
select p.col1, p.col2, p.lookupkey,
(select lkp.description from lookup lkp
where lkp.Pkey = p.lookupkey) as p_description)
from t_parent
Datasource: dsParent
FieldsVisible: lookupcolumn=False

Lookup dataset, qLookup
select PKey, Description
from Lookup
Keysource: dsParent
KeyLinks: lookup.Pkey=Parent.lookupkey
KeyDescLinks: Lookup.Description=p_description

Helen