我正在尝试在Delphi中建立一些类关系。
在其他语言(例如C#,PHP等)中,这些关系没有问题,但是在Delphi中,我有一个循环引用错误。
为什么在Delphi中而不是C#中会发生此错误?其他语言如何以及为什么不能处理循环引用而Delphi无法处理呢? C#如何处理呢?
在不使用界面或单个单元的情况下,Delphi是否有解决方案?
Delphi
Dad.pas
unit Dad;
interface
uses
System.Generics.Collections,Child;
type
TDad = class
private
{ private declarations }
FName: string;
FChildren: TObjectList<TChild>;
protected
{ protected declarations }
public
{ public declarations }
property Name: string read FName write FName;
property Children: TObjectList<TChild> read FChildren write FChildren;
end;
implementation
end.
Child.pas
unit Child;
interface
uses
Dad;
type
TChild = class
private
{ private declarations }
FName: string;
FDad: TDad;
protected
{ protected declarations }
public
{ public declarations }
property Name: string read FName write FName;
property Dad: TDad read FDad write FDad;
end;
implementation
end.
CSharp
Dad.cs
using System;
using System.Collections.Generic;
using System.Text;
using CircularReferenceTest.SecondNamespace;
namespace CircularReferenceTest.FirstNamespace
{
public class Dad
{
public String Name { get; set; }
public IList<Child> Children { get; set; }
}
}
Child.ps
using System;
using System.Collections.Generic;
using System.Text;
using CircularReferenceTest.FirstNamespace;
namespace CircularReferenceTest.SecondNamespace
{
public class Child
{
public String Name { get; set; }
public Dad Dad { get; set; }
}
}