Subject Re: [IBO] TIB_LookupCombo - Join Tables - too ambitious??
Author Helen Borrie
At 07:18 PM 28-09-02 -0400, you wrote:
>I have asked this question before (or something that sounds the same)...Ms.
>Borrie stated that the correct approach was as she suggested in her last
>comment, do not use a lookup combo, just a regular combo and use that value
>to pass the data to the insert for your table update.

Note that this advice was particular to the case being discussed in that
thread, not a general advice....that user was trying to make the Lookup
relationship work on a manufactured relationship which was improperly
modelled. The general advice would be to use a lookupcombo on a properly
modelled Keysource-Lookup relationship.

>I brought up the same
>issue in the ib-support group and they stated that this operation can only
>be done on the user end, not the backend.

Unfortunately, you didn't really state your problem adequately in the
ib-support group - but there you were not describing a Keysource-Lookup
relationship but a master-detail one.

>So the user has to use the
>dropdown list of ids to pick one in order to insert a record into another
>table...the foreign key link is established after the data is inserted, when
>the user attempts to look up the associated table data.

A dropdown list is not a great way to form master-detail links, since it
forces the user to determine a relationship that you have already defined
in the database by
foreign key.

>It is not necessary
>to establish it for the purposes of actually inserting data, only that the
>correct (i.e., id of the member from the drop-down list in a regular combo)
>be inserted into the record...i hope this helps, even more, i hope this

Be clear whether your relationship is Keysource-Lookup or master-detail.

Here was your description of your problem as stated in ib-support.

--There is a "master" table CLIENT, primary key CLIENTPK (a column, there are
many others too).
--There is a "detail" table INSURANCE, with a foreign key, CLIENTFK (a column,
there are many others too). There are many insurance records per client.
--I would like to insert a new record in INSURANCE with the CLIENTFK filled
with CLIENT.CLIENTPK. The user has already used a SELECT * FROM CLIENT
WHERE CLIENTPK = :clientpk. [snip....see [A] below]
especially when i have multiple SELECTS for clients?

Now, if you need to treat this as a master-detail relationship, here is how
you would do it.

If you are using native (TIB_*) data access:

Set the Mastersource property of the INSURANCE query (the detail) to the
TIB_Datasource which points to the CLIENT query. Set the MasterLinks
property of the INSURANCE query as


Now, IBO will automatically write the CLIENTPK value into the INSURANCE
record's CLIENTFK field when you insert a new record into the detail set.

If you are using the TIBO* components (TDatasource-compatible) you are
subject to the same limitations as the Delphi VCL because your linking
master and detail columns do not have the same fieldname. You will need to
make your INSURANCE query a parameterised query, where the link column is
passed to the parameter, viz.

SELECT <other fields>, CLIENTFK

Set the Datasource property of this query to the TDatasource which points
to the CLIENT query.

In the AfterScroll event of the INSURANCE query, assign the parameter:

qryInsurance.ParamByName('CLIENTFK').AsInteger := qryClientCLIENTPK;

As with the native structures, IBO will now take care of establishing the
relationship when you insert new rows into the INSURANCE query.


In your ib-support posting, you said:
--The problem is complicated further by: what if
the user is running multiple SESSIONS (i think this is the meaning of
session), with multiple SELECT queries as above, open in multiple windows.

This question puzzled me.
A single user doesn't typically run multiple sessions.
Could you provide a description of the scenario you are referring to here?