Accessing the Master-Detail Connection in Delphi

I have 2 tables that are related to using the master-detail join. I need the join to be inverted when creating Form2, so the main table becomes the details table, and the details table becomes the main table.

I tried to do this, and the program compiles, but does not work the way I want it (the previous connection is interrupted, but it is not reversed, so the kinda program works the same as the tables are not connected at all)

    Form1.ADOTableDetail.MasterSource.Destroy;
    Form1.ADOTableMaster.MasterSource :=  Form1.DataSourceDetail;
    Form1.ADOTableMaster.MasterFields := 'the_field_that_connects_them';

Any ideas on how I can achieve this?

+3
source share
3 answers

Do not destroy MasterSource!

To break the do ratio

Form1.ADOTableDetail.MasterSource:= nil;
Form1.ADOTableDetail.MasterFields:= '';

than use this to redirect MasterDetail

Form1.ADOTableMaster.MasterSource :=  Form1.DataSourceDetail;
Form1.ADOTableMaster.MasterFields := 'the_field_that_connects_them';

.Destroy , .Free.
Free , , Free ing , .

+6
procedure TForm1.ExchangeMasterDetail;
begin
  ADOTableDetail.Close;
  ADOTableMaster.Close;
  ADOTableMaster.MasterFields := ADOTableDetail.IndexFieldNames;
  ADOTableMaster.IndexFieldNames := ADOTableDetail.MasterFields;
  ADOTableDetail.IndexFieldNames := '';
  ADOTableDetail.MasterFields := '';
  ADOTableDetail.MasterSource := nil;
  ADOTableMaster.MasterSource := DataSourceDetail;
  ADOTableDetail.Open;
  ADOTableMaster.Open;
end;
+3

Just set the master table Activefor false.

Then do what you want and set it to true.

0
source

All Articles