by Maxim Shir » Wed, 18 Oct 2006 22:37:16
Hi.
Nested dataset is availbale as a TDataSetField field. For example if your
nested dataset is called DetailCDS you can use
var detail : TDataSet;
...
detail := (MasterCDS.FieldByName('DetailCDS') as TDataSetField);
Now detail is your detail dataset corresponding to a selected record in the
master.
As for filters, you cannot specify detail fields in filter strings. But you
can supply an OnFilterRecord event handler. Something like this:
procedure TYourDatamodule.MasterCDSOnFilterRecord(DataSet: TDataSet; var
Accept: Boolean)
var
detail : TDataSet;
begin
detail := MasterCDS.FieldByName('DetailCDS') as TDataSetField;
if (DataSet['SomeField'] = SomeValue) and (detail.Locate('OtherField',
OtherValue, []) then begin
Accept := true;
end elese begin
Accept := false;
end
end;
This filter approximatelly correspond to
select * from master m
where
m.SomeField = :SomeValue
and
exists (select * from detail d where d.NumRegMaster = m.NumReg and
d.OtherField = :OtherValue)
Maxim.
> Hi>
> I am developing a database application with clientdatasets that loads an>
> saves it's data directly to and from a .cds file. I am not using an>
> database server>
> I have a master clientdataset and a detail clientdataset>
> The detail clientdataset is a datasetfield of the master clientdataset>
> The detail clientdataset is a nested dataset of the master clientdataset>
> The master clientdataset has a field named NumReg of integer type>
> The detail clientdataset has a field named NumRegMaster of integer type>
> If a detail record is inserted on the detail clientdataset the
NumRegMaste>
> field of this record receives the same value of the NumReg field of th>
> corresponding record of the master clientdataset>
> I want to filter the master clientdataset based on the values of some
field>
> of the detail dataset>
> I am using the Filter and Filtered properties of the master clientdataset
t>
> build the filter at runtime based on the filter options selected by th>
> user>
> How can I access the detail fields of the detail clientdataset from th>
> master clientdataset >
> How can I filter the records of the master clientdataset based on the
fiel>
> values of the detail clientdataset >
> Thank you for any help>
> Marcelo>
>