Master/detail with IBQuery->DataSetProvider->ClientDataSet.

Hi all,

I am testing a master/detail with IBQuery->DataSetProvider->ClientDataSet.

For project constraints I will have to create the objects at run time.

For the time being (test) I am using the visual objects, assigning at run
time only few properties, how the  following piece of code shows:

-------------------

begin

  IBDatabase1.Connected := True;

  IBTransaction1.StartTransaction;

  with IBQuery1 do

  begin

    SQL.Clear;

    SQL.Add('select * from rc_pre_testa'); // master data

    Open;

    ClientDataSet1.FieldDefs.Clear;

    for i := 0 to FieldCount - 1 do

    begin

      with ClientDataSet1.FieldDefs.AddFieldDef do

      begin

        Name := IBQuery1.Fields[i].FieldName;

        DataType := IBQuery1.Fields[i].DataType;

        if IBQuery1.Fields[i].DataType = ftString then

          Size := IBQuery1.Fields[i].DataSize;

      end;

    end;

  end;

  ClientDataSet1.Open;

  with IBQuery2 do

  begin

    SQL.Clear;

    SQL.Add('select * from rc_pre_dettaglio'); // detail data

    SQL.Add('where prot_ver = :prot_ver');

    Open;

    ClientDataSet2.FieldDefs.Clear;

    for i := 0 to FieldCount - 1 do

    begin

      with ClientDataSet2.FieldDefs.AddFieldDef do

      begin

        Name := IBQuery2.Fields[i].FieldName;

        DataType := IBQuery2.Fields[i].DataType;

        if IBQuery2.Fields[i].DataType = ftString then

          Size := IBQuery2.Fields[i].DataSize;

      end;

    end;

  end;

  with ClientDataSet2 do

  begin

    MasterSource := DataSource1;

    MasterFields := 'PROT_VER';

    IndexFieldNames := 'PROT_VER';

  end;

  ClientDataSet2.Open;

  IBQuery1.Close;

  IBQuery2.Close;

  IBTransaction1.Commit;

end;

------------------------------

Without changing this code and assigning the ClientDataSet2.MasterSource
property to DataSource1 by Object Inspector the program works fine, and I
see changing the detail data (in a DBGrid) according with the master
selected record.

If I delete the Object Inspector property assignation
ClientDataSet2.MasterSource to DataSource1, the master DBGrid shows the
right records, but the detail only the records related to the first master
record; for all others records the detail DBGrid is empty, selecting again
the first master DBGrig record, the detail DBGrid shows again the right
related records.

Does anybody help me to understand why, and where is the mistake?

TIA

Stefano