



Você pode verificar a propriedade “DataSetField” do detalhe / aninhado ou acessar a propriedade “NestedDataSet” do conjunto de dados mestre.
Código de exemplo para obter o nome do campo “link”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | function GetCDSDLinkFieldName(cds: TClientDataSet): string; var i: Integer; cdsDetail: TClientDataSet; begin Result := EmptyStr; cdsDetail := nil; if Assigned(cds.DataSetField) then cdsDetail := cds; if not Assigned(cdsDetail) and (cds.FieldCount > 0) then begin i := 0; while not Assigned(cdsDetail) and (i < cds.FieldCount) do begin if cds.Fields[i].DataType = ftDataSet then cdsDetail := TClientDataSet(TDataSetField(cds.Fields[i]).NestedDataSet); Inc(i); end; end; if Assigned(cdsDetail) then Result := cdsDetail.DataSetField.FieldName; end; |
Exemplo de uso:
1 2 3 4 5 | procedure ... begin ShowMessage(GetCDSDLinkFieldName(cdsMaster)); ShowMessage(GetCDSDLinkFieldName(cdsDetail)); end; |
Referência: https://stackoverflow.com/questions/3155061/how-to-find-the-foreign-key-field-name-on-a-nested-tclientdataset