루트 노드로 만든 이진 트리 클래스가 있는데 코드에 필요에 따라 노드를 추가 할 수 있지만 노드를 가리킬 때 문제가 있습니다. TNodePtr과 호환되지 않으며 TNode와 호환되지 않는 유형입니다. 현재이 호환되지 않는 유형이 정렬되면 작동해야하는 노드를 삭제하는 재귀 적 방법이 있습니다. 감사.Delphi Delete TNode, 호환되지 않는 유형 TNodePtr
Destructor TTree.Destroy;
procedure FreeSubnodes(Node: TNodePtr);
begin
if Assigned(Node.Left) then
FreeSubnodes(Node.Left);
if Assigned(Node.Right) then
FreeSubnodes(Node.Right);
Delete(Node);
end;
begin
FreeSubnodes(Root);
inherited;
end;
편집 2010년 4월 3일 (50) [경고] SystemBuild.pas : 방법 "파괴"기본 유형의 가상 메소드를 숨기는 'TObject의' [오류]에서는 SystemBuild 주어진 오류가 이쪽 .pas (84) : 호환되지 않는 유형
라인 84는 삭제 (노드)입니다. 이 같은
type
TNodePtr = ^TNode;
TNode = Record
Data:String;
Left:TNodePtr;
Right:TNodePtr;
end;
그리고 나무 :
는이 같은 노드 선언 된 포인터를 사용 노드 역 참조에Type
TTree = Class
Private
Root:TNodePtr;
Public
Function GetRoot:TNodePtr;
Constructor Create;
Destructor Destroy;
end;
TNode 및 TNodePtr 선언을 표시해야합니다. –
* 전체 오류 메시지 *를 인용하고 어떤 라인이 발생하는지 알려주십시오. –
이제 오류 및 선언을 편집에 추가했습니다. 미안 나는 처음에 약간의 서두를했다. – BookOfGreg