Page 1 of 1

ParamByName in Master/Detail

Posted: 27.11.2017, 11:16
by vejrous
Hi, I have 2 TQuery components conected with TQuery2.Datasource property.

TQuery1, MasterSQL:
SELECT id, field1, field2
FROM master


TQuery2, DetailSQL:
SELECT field1, master_id
FROM detail
WHERE master_id = :id


Question: is TQuery2.ParamByName('id') automaticly set, when using this type of connection?

Purpouse:
I connect TQuery2 with Datasource property when records should dynamicly change or with ParamByName when other type required (usually some modal form).

So when you call:

Code: Select all

procedure TDatamodule.qryQuery2BeforePost(DataSet: TDataSet);
begin
  // this part should not be needed
  if Assigned(qryQuery2.DataSource) then
    fldQuery2ID.AsString := qryQuery2.DataSource.DataSet.FieldByName('id').AsString
  // this should be enought for both versions  
  else
    fldQuery2ID.AsString := qryQuery2.ParamByName('id').AsString;
end;
Is this how Zeos works or am I something missing?

Re: ParamByName in Master/Detail

Posted: 28.11.2017, 09:10
by marsupilami
Hello Vejrous,

usually I implement that kind of thing on my own in the after scroll event of the master dataset and in the before post of the detail dataset. But there is a (possibly outdated) documentation on how to use master - detail in Zeos. Take a look at the Documentation Collection, Topic "Master/Detail with ZEOS Library", Page 21. But I have to admit that although I compiled the documentation, I still didn't get around to testing it. Please let me know if this helps you or not.

With best regards,

Jan

Re: ParamByName in Master/Detail

Posted: 28.11.2017, 14:44
by Fr0sT
In short, M-D relationship in Zeos is achieved by this:

Code: Select all

  object qDetail: TZQuery
    DataSource = dsMaster
    MasterFields = 'ID'
    LinkedFields = 'RecordID'
  end
Where 'ID' is a key field in Master and 'RecordID' is FK field of Detail