Subject Re: [IBO] TIB_Query and KeyLinks via Delphi Code
Author Helen Borrie
At 02:03 PM 11/03/2003 -0800, you wrote:
>Hi Group;
>
>I am getting the following error when I try to set
>TIB_Query KeyLinks via code in Delphi.
>
>Project __ raised exception class EIB_Error with
>message 'Invalid KeyLink Entry' TBL_AK.AFF_CODE
>Process stopped, Use step or Run to continue.
>
>I am trying to do this in code because the user has
>the ability to select from 52 tables and each table
>has the same 3 search fields (ID, Name, City). It
>would be difficult to arrange 156 TIB_Query Components
>on a data module page. This is to get 9
>TIB_LookupCombo Boxes to work.
>
>Some of my code is as follows:
>
> KL_Main : TIB_StringList;
>...
> tblName : string;
>...
> tblName := 'TBL_AK';
>...
> KL_Main := TIB_StringList.Create;
> KL_Main.Add((tblName + '.AFF_CODE'));
> KL_Main.Add((tblName + '.DEDUCT_CODE'));
> KL_Main.Add((tblName + '.ORG_CODE'));
> KL_Main.Add((tblName + '.OFFICE_CODE'));
> KL_Main.Add((tblName + '.ASSET_CODE'));
> KL_Main.Add((tblName + '.INCOME_CODE'));
> KL_Main.Add((tblName + '.FILING_CODE'));
> KL_Main.Add((tblName + '.ACCT_PRDS'));
> KL_Main.Add((tblName + '.FOUND_CODE'));
>...

You don't need this for the "ordinary" use of KeyLinks: once the ib_query
object exists, the KeyLinks structure is already created.

Just do

...with MyQuery.KeyLinks do
Add('AFF_CODE');
Add('DEDUCT_CODE');
.... and so on


> mainDM.ibq_Main.KeyLinks := KL_Main;

NB. You should use Assign to pass the strings of one TStrings to another.


>This coding generates the error. I went to the help
>file for TIB_StringList Object and now I am thoroughly
>confused. Is the help file telling me that for each
>keyLink entry, the following is required (using the
>syntax from the help file)?
>
><link entry> ::= <link name>=<link value>
><link name> ::= [<table name>.] <column name>
><link value> ::= (<string literal>|<param list>)

This isn't syntax, it's a descriptive convention for parsers. I know it's
confusing, but the TI sheet "Working with Fields & Params" explains how to
use the link entry convention for applying the various types of
dataset-to-dataset field linkages at runtime, where you can't otherwise get
to them as distinct properties.


>What would be a valid code entry in Delphi?
>
> KL_Main.Add((linkEntry1=linkName1=linkValue1));
>
>where linkEntry1 is an arbitrary name,
>linkName1 = affiliation = TBL_AK.
>linkValue1 = AFF_CODE
>all assigned to TStrings prior to the add procedure.

You don't need this stuff for KeyLinks.

If you are applying the "two-sided keylinks" to implement the relationship
from a lookup dataset to a column in a parent dataset which is pointed to
via the KeySource property, then your strings need to be

...
with MyLookupQuery do
KeySource := TheParentQuery.Datasource;
with KeyLinks do
Add('AFF_CODE=TheParentTable.Aff_Code');
Add('DEDUCT_CODE=TheParentTable.Deduct_Code');
.... and so on
You can optionally include qualifiers for the lookup table keys but for the
parent table keys they are mandatory. I always use qualifiers on both
sides myself.

But it's not clear which application of KeyLinks you are having the
problems with...

Helen