Filtering A TClientDataSet On A NestedDataSet Fiel

2019-05-10 10:10发布

问题:

I have a small application I am working on that is almost finished thanks to those who have assisted me here. I have one last task however. I need to be able to Filter a TClientDataSet on a NestedDataSet field.

ClientDataset1
Field0: Name (Lake Name)
ClientDataset2
Field0: Species (Fish Species)

type
  TDataModule1 = class( TDataModule )
    ClientDataSet1: TClientDataSet;
    ClientDataSet2: TClientDataSet;
    ClientDataSet1Name: TStringField;
    ClientDataSet1County: TStringField;
    ClientDataSet1Town: TStringField;
    ClientDataSet1Area: TStringField;
    ClientDataSet1MaximumDepth: TStringField;
    ClientDataSet1MeanDepth: TStringField;
    ClientDataSet1MapFilename: TStringField;
    ClientDataSet1Species: TDataSetField;
    ClientDataSet2Species: TStringField;
    procedure DataModuleDestroy( Sender: TObject );
  private
    { Private declarations }
  public
    { Public declarations }
  end;

Data:
Nate Pond
    Brook trout
    Creek chub
    Golden shiner
Black Pond
    Brook trout
    Brown bullhead
    Common shiner
Lake Placid
    Lake trout
    Smallmouth bass
    Yellow perch

I need to to filter ClientDataset1 to show all lakes that have Brook trout in the ClientDataset Species field.

Filtered:
Nate Pond
    Brook trout
    Creek chub
    Golden shiner
Black Pond
    Brook trout
    Brown bullhead
    Common shiner

How can a filter (or other means) be created to accomplish this? Are there any third-party componets that will do this?

Thanks,

Bill

回答1:

Try adding an OnFilterRecord handler to the master dataset and use Locate on the nested dataset inside the handler to see if the record exists.