Hey wussup, im in a pascal class and I am currently working on a class assignment in which we have movie database program, the information for each movie is its name, length in minutes and year it came out. We have to use records to store the information. And my problem is that when I add a new movie, i dont know how to error check the name of the movie to the database and see if its already not there, when i type up a code i get "Operator is not overloaded"

Please respond so i can send you what i have so far and you can help me :)

program movies;

{$mode objfpc}{$H+}

uses
  Classes,
  SysUtils;
type
  TMovie = record
    Name: string;
    RunTime: Integer;
    Year: Integer;
  end;
  
  TMovies = array[0..4] of TMovie;
var
  I: Integer;
  MyMovies: TMovies;
begin
  // Initialize the database
  MyMovies[0].Name := 'Rocky';
  MyMovies[0].RunTime := 119;
  MyMovies[0].Year := 1976;
  
  MyMovies[1].Name := 'Titanic';
  MyMovies[1].RunTime := 194;
  MyMovies[1].Year := 1997;

  MyMovies[2].Name := 'Star Wars';
  MyMovies[2].RunTime := 121;
  MyMovies[2].Year := 1977;
  
  MyMovies[3].Name := 'Batman';
  MyMovies[3].RunTime := 126;
  MyMovies[3].Year := 1989;
  
  MyMovies[4].Name := 'True Grit';
  MyMovies[4].RunTime := 128;
  MyMovies[4].Year := 1969;

  // Find the index for the movie Star Wars
  for I := Low(MyMovies) to High(MyMovies) do
  begin
    if UpperCase(MyMovies[I].Name) = 'STAR WARS' then
    begin
      writeln;
      writeln('Found Star Wars at index: ' + IntToStr(I));
      writeln;
    end;
  end;
end.

thanks for the reply but thats not what im really looking for, here is my code

program p6;
type
movie = record
name:String;
hours:real;
year:integer;
end;
mov_arr = array[1..100] of movie;
var
{These should be the only global variables}
data : mov_arr;
size:integer;
ans:integer;
function add_mov(var name:string; data:mov_arr):movie;
var
tmp:movie;
ans:string;
x:boolean;
i: integer;
begin
x:=false;
repeat
writeln('Enter Movie Name');
readln(tmp.name);
writeln('Enter Length of Movie in minutes');
readln(tmp.hours);
writeln('Enter the year the movie was released');
readln(tmp.year);
writeln('Is this correct?');
writeln(tmp.name, tmp.hours, tmp.year);
until ans = 'yes';
add_mov := tmp;
end;
procedure write_file(data:mov_arr; size:integer);
var
fp:text;
name:string;
i:integer;
begin
writeln('Enter File');
readln(name);
assign(fp, name);
rewrite(fp);
for i:=1 to size do
begin
writeln(fp, data.name);
writeln(fp, data.hours);
writeln(fp, data.year);
end;
close(fp);
end;
procedure print_file();
var
fp:text;
name1:string;
name:string;
hours:real;
year:integer;
begin
writeln('Enter file name');
readln(name1);
assign(fp, name1);
reset(fp);
While not eof(fp) do
begin
readln(fp, name);
readln(fp, hours);
readln(fp, year);
writeln(name);
writeln(hours);
writeln(year);
end;
close(fp);
end;
begin{main}
{initial to size zero}
size:=0;
repeat
writeln;
writeln;
writeln('Options');
writeln('1: Display database');
writeln('2: Add movie');
writeln('3: Delete movie');
writeln('4: Sort');
writeln('5: Read from file');
writeln('6: Write to file');
writeln('0: To quit');
readln(ans);
{Each option must be a function/procedure call}
if ans = 1 then
{ Display all the  movies' name length and year}
if ans = 2 then
{ Add a movie to the database but only if is isn't already in there.}
if ans = 3 then
{ Ask the user for a the name of the movie and delete it.
If it is not in the database, tell the user and do nothing}
if ans = 4 then
{ Ask the user how they want to sort: name, hours, or year
Then sort the database.  Don't worry about ties.}
{
For options 5 and 6, you will be reading from a file.
The format of the file is
name of movie
hours
year
Each file may have between 1 and 100 movies recorss
}
if ans = 5 then
{
Ask the user for a file name and read the records from the file.
The database is initialized to the contents of the file and
any pre-existing data in the database is lost.
}

if ans = 6 then
{
Ask the user for a filename and write the data to the file in the proper format}
until ans = 0;

end.{main}

Edited 3 Years Ago by happygeek: fixed formatting

If you modify what I posted slightly, it will work in your application.

{ Change to procedure. You don't use the return value for anything. }
procedure add_mov(var name:string; data:mov_arr);
var
   tmp:movie;
   ans:string;
   i: integer;
   MovieFound: boolean;
begin
   repeat
      writeln('Enter Movie Name');
      readln(tmp.name);
      writeln('Enter Length of Movie in minutes');
      readln(tmp.hours);
      writeln('Enter the year the movie was released');
      readln(tmp.year);
      writeln('Is this correct?');
      writeln(tmp.name, tmp.hours, tmp.year);
   until ans = 'yes';

   { Search the array for a movie title matching the one the user entered. }     
   MovieFound := False;
   for I := Low(data) to High(data) do
   begin
      if UpperCase(data[I].Name) = UpperCase(tmp.name) then
      begin
         MovieFound := True;
         Break;
      end;
   end;
   
   { If the movie title wasn't found, add it to the array. }
   if not MovieFound then
   begin
      { Add the movie to the array. }
      
      { You might consider using a dynamic array,
        a TList object, or a linked list instead of
        using a static array. How do you know how
        many movies are already in the array? }
   end;
end;
This article has been dead for over six months. Start a new discussion instead.