[Lazarus] Master/Detail Relation

Leonardo M. Ramé l.rame at griensu.com
Sat Apr 16 23:39:05 CEST 2011

On 2011-04-16 15:56:19 -0300, Leonardo M. Ramé wrote:
> Hi, I was looking at SqlDb components and I can't find any property to
> link two datasets in a Master/Detail relation, as in Delphi.
> Is such feature already implemented? any tutorial/wiki?.
> Thanks in advance,
> -- 

I found the solution. 

For the record:

SqlQuery1 (master)
SqlQuery2 (detail)

In SqlQuery2.Sql.Text I had to add a "where" condition with a param, for

select * from a_table where a_field = :field_from_query1

The param must be a Field from SqlQuery1.

Then, by code, i had to the param type:

SQLQuery2.ParamByName('field_from_query1').DataType := ftInteger; 

The last step is to point SqlQuery2.DataSource to a TDataSource
associated to SqlQuery1. In my case I have two TDbGrids in form1, each
grid with a TDataset pointed to SqlQuery1 and SqlQuery2, so in
SqlQuery2.DataSource I assigned "form1.datasource1", and that's it.

Leonardo M. Ramé

More information about the Lazarus mailing list