How can I find if a DataSet is the master in a master/detail relationship in Delphi?
Asked Answered
S

1

6

I want to create a "Duplicate Record" action which when invoked, duplicates current record in any TDataSet descendant. How can I find out if the dataset is the master dataset of a master/detail relationship? With TClientDataSet it's rather easy, but I need this action to be used with all descendants of TDataSet.

Stepmother answered 28/8, 2012 at 10:16 Comment(0)
U
10

You should call TDataSet.GetDetailDataSets method. If the list is not empty, then this dataset is the master dataset for the datasets in the list. For example:

var
  oDetails: TList;
  lIsMaster: Boolean;
...
  oDetails := TList.Create;
  try
    myDataSet.GetDetailDataSets(oDetails);
    lIsMaster := oDetails.Count > 0;
  finally
    oDetails.Free;
  end;
Unknow answered 28/8, 2012 at 11:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.