0
votes

I need help with creating my music player, I'm receiving the same error and can't seem to get past it. Thank you. I've attached my code below, as well as my errors.

Errors:

Free Pascal Compiler version 2.6.4 [2014/02/26] for i386 Copyright (c) 1993-2014 by Florian Klaempfl and others Target OS: Darwin for i386 Compiling MusicPlayer.pas

MusicPlayer.pas(82,37) Error: Incompatible type for arg no. 1: Got "ShortString", expected "Album"

MusicPlayer.pas(138,31) Error: Incompatible type for arg no. 1: Got "albumArray", expected "Album"

MusicPlayer.pas(164,44) Error: Incompatible type for arg no. 1: Got "albumArray", expected "Album"

MusicPlayer.pas(174) Fatal: There were 3 errors compiling module, stopping Fatal: Compilation aborted Error: /usr/local/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)

    program MusicPlayer;
uses TerminalUserInput;

type
    Track = record
       trackName: String;
       location: String;
    end;

    TrackArray = array of Track;

    Album = record
       albumName: String;
       artistName: String;
       genre: String;
       track: TrackArray;
       // key: Integer;
       trackNum: Integer;
       fileName: String;
    end;

    albumArray = array of Album;


function GetAlbums(): albumArray;
var
    // anAlbum: Album;
    //albums: albumArray;
    fileName: String;
    myFile: TextFile;
    numOfAlb: Integer;
    trackNum: Integer;
    i: Integer;
    j: Integer;
begin
    fileName := ReadString('Enter filename: ');
    AssignFile(myFile, fileName);
    // AssignFile(myFile, 'albums.dat');
    Reset(myFile);
    ReadLn(myFile, numOfAlb);
    setLength(result, numOfAlb);
    for i:= 0 to High(result) do
    begin
        ReadLn(myFile, result[i].albumname);
        ReadLn(myFile, result[i].artistName);
        ReadLn(myFile, result[i].genre);
        ReadLn(myFile, trackNum);
        setLength(result[i].track, trackNum);
        for j:= 0 to trackNum -1 do
        begin
            ReadLn(myFile, result[i].track[j].trackName);
            ReadLn(myFile, result[i].track[j].location);
        end;
    end;
end;

procedure DisplayAlbum(a: Album);
var
    //t: Track;
    i: Integer;

begin
    WriteLn('Album name is: ', a.albumName);
    WriteLn('Album artist name is: ', a.artistName);
    WriteLn('Album genre is: ', a.genre);
    WriteLn('Number of tracks are: ', a.trackNum);
    for i:= 0 to High(a.track) do
    begin
        WriteLn('Track name is: ', a.track[i].trackName);
        WriteLn('Album name is: ', a.track[i].location);
    end;
end;


function PrintAllGenres(albums: albumArray): albumArray;
var
    i: Integer;

begin
    for i := 0 to High(albums) do
    begin
        DisplayAlbum(albums[i].genre);
    end;

end;



procedure SelectAlbum(const albums: albumArray);
var
   val: Integer;
   i: Integer;
begin
   WriteLn('<< Welcome to the Track Player >>');
   val := ReadInteger('Enter an Album''s key number: ');
   for i := 0 to High(albums) do
   begin
     WriteLn('Album is now playing.');
   end;
   if (i > High(albums)) then
   begin
      WriteLn('Album was not found, now returning to Main Menu ');
   end;
end;

function UpdateAlbum(a: Album): Album;
begin
    a.albumName := ReadString('Please enter a new name for this album: ');
    a.genre := ReadString('Please enter a new genre for this album: ');
end;

// function UpdateAlbums(): albumArray;
// var
//    val: Integer;
//    i: Integer;
// begin
//    WriteLn('<< Album Updater >>');
//    val := ReadInteger('Enter an Album''s key number: ');
//    if (val = True) then
//         WriteLn('Album was found.')
//    else
//           WriteLn('Album was not found, now returning to Main Menu ');
// end;


procedure DisplayAlbums(albums: albumArray);
var
    val: Integer;
begin
   repeat
    WriteLn('<< Displaying Albums >>');
    WriteLn('1. Display all albums');
    WriteLn('2. Display genre');
    WriteLn('3. Return to main menu');
    val := ReadInteger('Enter a number to enter menu: ');

    case val of
        1: DisplayAlbum(albums);
        2: PrintAllGenres(albums);
    end;

  until val = 3;
end;


procedure Main();
var
    albums: albumArray;
    val: Integer;
begin
    repeat
        WriteLn('<< Text Music Player Menu >>');
        WriteLn('1. Read in Albums');
        WriteLn('2. Display Albums');
        WriteLn('3. Select an Album to play');
        WriteLn('4. Update an existing Album');
        WriteLn('5. Quit');
        val := ReadInteger('Enter a number to enter menu: ');

        case val of
            1: albums := GetAlbums();
            2: DisplayAlbums(albums);
            3: SelectAlbum(albums);
            4: albums := UpdateAlbum(albums);

        end;

    until val = 5;
end;

begin
    Main();
end.
1

1 Answers

2
votes

In your code you have written

procedure DisplayAlbum(a: Album);

which means that you need to pass an Album to the procedure, but on line 82 you have written

    DisplayAlbum(albums[i].genre);

genre is a field of an Album while you should pass a whole Album

Change line 82 to

    DisplayAlbum(albums[i]);

I leave the other errors for you yourself to work out, the errors are very similar, and you should now be able to sort them out. As I told you yesterday, you may want to (or actually, need to) speak with your tutor to get a better understanding.