在Delphi中反转Master-Detail连接

Rad*_*ant 3 database delphi tadotable

我有2个表使用主从细节连接连接.我需要在创建Form2时反转连接 - 因此主表成为详细信息表,详细信息表成为主表.

我尝试这样做,程序编译,但不能按我想要的方式工作(之前的连接中断,但它没有反转,所以程序有点像表格根本没有连接):

    Form1.ADOTableDetail.MasterSource.Destroy;
    Form1.ADOTableMaster.MasterSource :=  Form1.DataSourceDetail;
    Form1.ADOTableMaster.MasterFields := 'the_field_that_connects_them';
Run Code Online (Sandbox Code Playgroud)

关于如何实现这一目标的任何想法?

Joh*_*ica 6

不要破坏MasterSource!

为了打破关系呢

Form1.ADOTableDetail.MasterSource:= nil;
Form1.ADOTableDetail.MasterFields:= '';
Run Code Online (Sandbox Code Playgroud)

而不是使用它来重新路由MasterDetail

Form1.ADOTableMaster.MasterSource :=  Form1.DataSourceDetail;
Form1.ADOTableMaster.MasterFields := 'the_field_that_connects_them';
Run Code Online (Sandbox Code Playgroud)

也不要.Destroy直接打电话,.Free而是使用.
Free会额外检查你的参考文件是否Free为零,以防止一些访问冲突.