I've 2 tables that are connected using master-detail connection. I want the bond corrected on development of Form2 - therefore the master table becomes the detail table, and also the detail table becomes the actual table.
I attempted carrying this out, and also the program compiles, but does not work generate an income would like it to (the prior connection breaks, but it is not corrected, therefore the program kinda works such as the tables aren't connected whatsoever):
Form1.ADOTableDetail.MasterSource.Destroy; Form1.ADOTableMaster.MasterSource := Form1.DataSourceDetail; Form1.ADOTableMaster.MasterFields := 'the_field_that_connects_them';
Any applying for grants the way i might accomplish this?
Don't destroy the MasterSource!
To be able to break the connection do
Form1.ADOTableDetail.MasterSource:= nil; Form1.ADOTableDetail.MasterFields:= '';
than make use of this to reroute the MasterDetail
Form1.ADOTableMaster.MasterSource := Form1.DataSourceDetail; Form1.ADOTableMaster.MasterFields := 'the_field_that_connects_them';
Also never call
.Destroy directly, use
Free does an additional determine when the reference you're
Freeing isn't nil, stopping some Access Violations.
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;