[Lazarus] SQLite: Several foreign keys

Luiz Americo Pereira Camara luizmed at oi.com.br
Sun Oct 19 17:24:11 CEST 2008


Usuario AnĂ³nimo wrote:
> I have three TDBGrids.
>
> Phone has two foreigns keys: Contact and Company. 
>

The automatic master/source relationship provided by MasterSource 
property will not work in this case.
You will need  to do manually.

- Clear the MasterSource/IndexFieldNames properties
- Create a procedure UpdatePhone and put

  PhoneDataset.Sql := 'Select * from PhoneTable where Contact = ' + 
ContactDataset.FieldByName('IdField').AsString + ' And ' +
  'Company = ' + ContactDataset.FieldByName('IdField').AsString;
  PhoneDataset.Close;
  PhoneDataset.Open;

- Call UpdatePhone inside OnAfterScroll events of ContactDataset and 
CompanyDataset

Some refinement may be needed to handle corner cases (no contact etc)

Luiz





More information about the Lazarus mailing list