//例1: 這是正確的
TClassA = class FIEld1: string;
FIEld2: Integer;
end;
TClassB = class
FIEld1: string;
FIEld2: Integer;
Field3: TClassA; {字段 FIEld3 的類型是剛剛新定義的 TClassA 類型}
end;
//例2: 這是錯誤的, 這裡有個順序問題
TClassA = class
FIEld1: string;
FIEld2: Integer;
Field3: TClassB; {字段 FIEld3 的類型是將要定義的 TClassB 類型}
end;
TClassB = class
FIEld1: string;
FIEld2: Integer;
end;
//例3: 解決方案 - 向前聲明
TClassB = class; {向前聲明}
TClassA = class
FIEld1: string;
FIEld2: Integer;
FIEld3: TClassB;
end;
TClassB = class
FIEld1: string;
FIEld2: Integer;
end;