//例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;