Board index » delphi » lookup field with multiple key fields

lookup field with multiple key fields

Hi

has anyone ever tried to define a lookup field with multiple key fields?

I did but it hasn't worked yet.

I've followed exactly the instructions in section 19-10 of the
developer's guide.

----------------------------------------------------------------------
Powersoft AG Informatik- & Automations-Engineering
http://www.powersoft.ch
Urs Fiore
Programmierer
fon ++41 (0)31 332 00 32
fax ++41 (0)31 332 00 46
                                                          \\///
mailto:u.fi...@powersoft.ch                              ('O O')
-------------------------------------------------------ooO-(_)-Ooo----

 

Re:lookup field with multiple key fields


Hi

has anyone ever tried to define a lookup field with multiple key fields?

I did but it hasn't worked yet.

I've followed exactly the instructions in section 19-10 of the
developer's guide. Afterwards my definition looks as follows:

object dm_Publications: Tdm_Publications
  ...
  object qry_T380: TQuery
    CachedUpdates = True
    ...
    SQL.Strings = (
      'SELECT ... '
        '       Dbo_t380.T360_TYP_PUB_ID, Dbo_t380.T410_CHAP_ID, ...'
    )
    UpdateObject = upd_T380
    ...
    object qry_T380T360_TYP_PUB_ID: TFloatField
      FieldName = 'T360_TYP_PUB_ID'
    end
    object qry_T380T410_CHAP_ID: TFloatField
      FieldName = 'T410_CHAP_ID'
    end
    ...
    object qry_T380T412_CHAP_F: TStringField
      FieldKind = fkLookup
      FieldName = 'T412_CHAP_F'
      LookupDataSet = qry_T412F
      LookupKeyFields = 'T360_TYP_PUB_ID;T410_CHAP_ID'
      LookupResultField = 'T412_CHAP'
      KeyFields = 'T360_TYP_PUB_ID;T410_CHAP_ID'
      Size = 80
      Lookup = True
    end
  end
  ...
  object qry_T412F: TQuery
    DatabaseName = 'OpSys1-BDE'
    SQL.Strings = (
      'SELECT ... Dbo_t412.T360_TYP_PUB_ID, Dbo_t412.T410_CHAP_ID,
Dbo_t412.T412_CHAP'
      '...'
    object qry_T412FT360_TYP_PUB_ID: TFloatField
      FieldName = 'T360_TYP_PUB_ID'
      Origin = 'T412.T360_TYP_PUB_ID'
    end
    object qry_T412FT410_CHAP_ID: TFloatField
      FieldName = 'T410_CHAP_ID'
      Origin = 'T412.T410_CHAP_ID'
    end
    object qry_T412FT412_CHAP: TStringField
      FieldName = 'T412_CHAP'
      Origin = 'T412.T412_CHAP'
      Size = 80
    end
  end
end

Excuting a little test program ends with:

EDatabaseError: DBLookupComboBox1: Field: 'T360_TYP_PUB_ID;T410_CHAP_ID'
not found.

Can anybody give me a hint what's wrong?

Thank,
U.Fiore

----------------------------------------------------------------------
Powersoft AG Informatik- & Automations-Engineering
http://www.powersoft.ch
Urs Fiore
Programmierer
fon ++41 (0)31 332 00 32
fax ++41 (0)31 332 00 46
                                                          \\///
mailto:u.fi...@powersoft.ch                              ('O O')
-------------------------------------------------------ooO-(_)-Ooo----

Re:lookup field with multiple key fields


I don't realy know what is written in developer's guide, but this is what
worked for me:

Table1:         Table2(LookupTable):
------------------      ----------------------
LookupKey1      Key1    
LookupKey2      Key2
...             ResultField
OtherData       ...
                OtherData

Table1 = table where you will define youre lookup field
Table2 = table from witch Table1 will get values for lookup field

After defining TTable components and adding a lookup field to Table1 (in
FieldsEditor select 'New field...' set name, type and set 'Field type' to
'Lookup', you will probably have to set info at the bottom, but at this
point  just set it to anything) do the following on that lookup field:

Make sure FieldKind = fkLookup,
set LookupDataset to Table2,
set KeyFields to LookupKey1;LookupKey2
set LookupKeyFields to Key1;Key2
and LookupResultField to ResultField.

Well this shoud work

Lucijan

Urs Fiore <u.fi...@powersoft.ch> wrote in article
<3801F899.E2D60...@powersoft.ch>...

Quote
> Hi

> has anyone ever tried to define a lookup field with multiple key fields?

> I did but it hasn't worked yet.

> I've followed exactly the instructions in section 19-10 of the
> developer's guide.

> ----------------------------------------------------------------------
> Powersoft AG Informatik- & Automations-Engineering
> http://www.powersoft.ch
> Urs Fiore
> Programmierer
> fon ++41 (0)31 332 00 32
> fax ++41 (0)31 332 00 46
>                                                           \\///
> mailto:u.fi...@powersoft.ch                              ('O O')
> -------------------------------------------------------ooO-(_)-Ooo----

Other Threads