我在某一个单元里依次声明了这两个类,程序中需要实现它们的相互引用,
主要表现在TNode的属性FChilds:TNodes和TNodes的属性FItems:array[0..MaxNodesSize] of TNode;
但是TNode的属性FChilds:TNodes编译不能通过(因为在此之前没有声明TNodes),有人能告诉我实现
相似的功能应该怎么作吗?不胜感激!!!
{TNode}
TNode=class (TWord)
private
FPart:string;
FMode:WideString;
FAttribule:string;
FTranslateOrder:integer;
FExplain:WideString;
FChilds:TNodes;
FParent:TNode;
procedure SetPart(Value:string);
procedure SetTranslateOrder(Value:integer);
procedure SetMode(Value:WideString);
procedure SetAttribule(Value:string);
function GetAttribule:string;
procedure SetExplain(Value:WideString);
function GetCenterWord:TWord;
procedure SetCenterWord(Value:TWord);
procedure SetChilds(Value:TNodes);
function GetLevel:integer;
public
constructor Create();
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure AddChild(Value: TNode);
procedure Init;
property Part: string read FPart write SetPart;
property Level: integer read GetLevel;
property Mode: WideString read FMode write SetMode;
property Attribule: string read GetAttribule write SetAttribule;
property TranslateOrder: integer read FTranslateOrder write SetTranslateOrder;
property Explain: WideString read FExplain write SetExplain;
property CenterWord: TWord read GetCenterWord write SetCenterWord;
property Childs: TNodes read FChilds write SetChilds;
property Parent: TNode read FParent;
end;
{TNodes}
TNodes=class (TPersistent)
private
FCount:Integer;
FParent:TNode;
FItems:array[0..MaxNodesSize] of TNode;
function GetItem(Index:integer):TNode;
procedure SetItem(Index:integer;Value:TNode);
function GetExplain:Widestring;
public
constructor Create;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function ArrayCopy(Start,Length:integer):TNodes;
procedure Add(Value: TNode);
property Parent: TNode read FParent;
end;
主要表现在TNode的属性FChilds:TNodes和TNodes的属性FItems:array[0..MaxNodesSize] of TNode;
但是TNode的属性FChilds:TNodes编译不能通过(因为在此之前没有声明TNodes),有人能告诉我实现
相似的功能应该怎么作吗?不胜感激!!!
{TNode}
TNode=class (TWord)
private
FPart:string;
FMode:WideString;
FAttribule:string;
FTranslateOrder:integer;
FExplain:WideString;
FChilds:TNodes;
FParent:TNode;
procedure SetPart(Value:string);
procedure SetTranslateOrder(Value:integer);
procedure SetMode(Value:WideString);
procedure SetAttribule(Value:string);
function GetAttribule:string;
procedure SetExplain(Value:WideString);
function GetCenterWord:TWord;
procedure SetCenterWord(Value:TWord);
procedure SetChilds(Value:TNodes);
function GetLevel:integer;
public
constructor Create();
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure AddChild(Value: TNode);
procedure Init;
property Part: string read FPart write SetPart;
property Level: integer read GetLevel;
property Mode: WideString read FMode write SetMode;
property Attribule: string read GetAttribule write SetAttribule;
property TranslateOrder: integer read FTranslateOrder write SetTranslateOrder;
property Explain: WideString read FExplain write SetExplain;
property CenterWord: TWord read GetCenterWord write SetCenterWord;
property Childs: TNodes read FChilds write SetChilds;
property Parent: TNode read FParent;
end;
{TNodes}
TNodes=class (TPersistent)
private
FCount:Integer;
FParent:TNode;
FItems:array[0..MaxNodesSize] of TNode;
function GetItem(Index:integer):TNode;
procedure SetItem(Index:integer;Value:TNode);
function GetExplain:Widestring;
public
constructor Create;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function ArrayCopy(Start,Length:integer):TNodes;
procedure Add(Value: TNode);
property Parent: TNode read FParent;
end;
TA = class;//预先定义一次 TB = Class
private
a:TA;
end; TA = Class
Private
b:TB;
end;implementationend.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TT = Class; TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
T:TT;
public
Procedure z;
end; TT = Class
private
f:TForm1; procedure a;
Public
Constructor Create(Ff:TForm1);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
t:=TT.Create(Self);
end;{ TT }procedure TT.a;
begin
if f<>nil then f.z;
end;constructor TT.Create(Ff: TForm1);
begin
f:=ff;
end;procedure TForm1.z;
begin
showmessage('test');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if t<>nil then
t.a;
end;end.
可以互相调用
在delphi开发指南里有讲