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?

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;

Open in new window

Untitled.jpg
Prima12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dagan HooverDeveloperCommented:
First off:

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.
0
Dagan HooverDeveloperCommented:
This is the best way you could probably check if the tree is invalid.

Since we are reading from a text file for records the address for a string can't be 0(nil). So we can only check to see if the entire tree exists(Assigned) and if the length of the strings are 0(after removing whitespace).
procedure findPhrase (t: MelodyTree);  //Write an inorder traversal using a stack
begin
  //If T is nil or the length of the title or phrase is 0
  If (Not(Assigned(T)) And ((Length(Trim(T^.title)) = 0) Or (Length(Trim(T^.phrase)) = 0)) Then
    begin
    Exit;
  end;
  writeln;
  writeln(' Phrases Stored In The Tree Are: ');
  write('[', t^.title, ']  :  ', '"', t^.phrase, '"');
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Prima12Author Commented:
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.

0
Prima12Author Commented:
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;

Open in new window

0
Prima12Author Commented:
Thanks for the suggestion. I have now opened a differnet question regarding the traversal of the tree.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.