Prima12
asked on
Display Woe In Delphi
For an assignment i am trying to display particular values stored in a record structure (of type ternary tree). The data is read in from a text file. There is no input value, it simply displays 2 select values from the tree.
I am trying to test to make sure it isnt emtpy. If its not, i want to display the values and then move to the next branches and so on until the values are empty.
I am getting lots of errors though which i dont understand. Can anyone help?
I am trying to test to make sure it isnt emtpy. If its not, i want to display the values and then move to the next branches and so on until the values are empty.
I am getting lots of errors though which i dont understand. Can anyone help?
procedure findPhrase (t:MelodyTree; n: integer);
begin
writeln;writeln;writeln;writeln;
writeln(' Phrases Stored In The Tree Are: ');
if (t^.title <> nil) and (t^.phrase <> nil) then
write('[', findPhrase(t^.title,n+1) '] : ', '"', findPhrase(t^.phrase,n+1) '"');
end;
// Record Structure
type MelodyTree = ^TreeNode;
TreeNode = record
upBranch: MelodyTree;
downBranch: MelodyTree;
sameBranch: MelodyTree;
title: string;
phrase: string;
end;
Untitled.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I still cant get any output though to begin checking if its working. I keep getting those errors that tell me that t^.title is incompatible. I dont understand why this happens, as all my books and notes use integers to navigate and i have no examples of any that use strings.
ASKER
This gives me no output at all. And i really really do not see why it wont.
procedure findPhrase (t: MelodyTree; n:integer); //Use inorder traversal
begin
writeln;
writeln(' Phrases Stored In The Tree Are: ');
If (Not(Assigned(T))) And ((Length(Trim(T^.title)) = 0) Or (Length(Trim(T^.phrase)) = 0)) Then
begin
findPhrase(t, n+1);
write('[', (t^.title), '] : ', '"', (t^.phrase), '"');
end;
end;
ASKER
Thanks for the suggestion. I have now opened a differnet question regarding the traversal of the tree.
t^.title <> nil
Your dereferencing the pointer with "^" so it's not a pointer value anymore so you can't compare it with. I'm not sure exactly how the structure is written to the text file when the values are empty. Maybe you could provide more insight to that.
-
Second when you recursively call
findPhrase(t^.title,n+1)
Your trying to give it a string variable and it wants a MelodyTree type. So depending on how this works you will use FindPhrase(T,N+1). You don't show how it actually finds the record so it's hard to see whats wrong.