Single Records

The first program demonstrates how single records are defined, filled with data, outputted and processed. TStudent has only two string fields and two integer fields, but some of the records used in database-type coursework are likely to have many fields and several additional types including char, real and Boolean. Usefully, if you type the record identifier followed by a full stop, you may be presented with a list of field names to choose from. Double click the left mouse button with the cursor over the required field name to add it to your code. The neat with Student1 do code (used here just for the output of Student1 data) requires field names without the identifier. prefix.

program SingleRecords;
{$APPTYPE CONSOLE}
uses
  SysUtils;
type
  TStudent = record
    Forename, Surname : string;
    TheoryMark, PracticalMark : integer;
  end;
var
  Student1, Student2 : TStudent;
begin
  //Hard coding a record
  Student1.Forename := 'Ann';
  Student1.Surname := 'Wells';
  Student1.TheoryMark := 68;
  Student1.PracticalMark := 72;
  writeln('Student 1');
  with Student1 do
    begin
      writeln('Name: ',ForeName,' ', Surname);
      writeln('Theory Mark: ', TheoryMark);
      writeln('Practical Mark: ', PracticalMark);
    end;
  writeln;
  writeln('Student 2');
  //Entering data into a record
  write('Forename? ');
  readln(Student2.Forename);
  write('Surname? ');
  readln(Student2.Surname);
  write('Theory Mark? ');
  readln(Student2.TheoryMark);
  write('Practical Mark? ');
  readln(Student2.PracticalMark);
  writeln;
  //Processing data in records
  if Student1.PracticalMark > Student2.PracticalMark then
    begin
      write(Student1.Forename,' ',Student1.Surname);
      writeln(' obtained the higher practical mark.');
    end
  else
    begin
      if Student1.PracticalMark < Student2.PracticalMark then
        begin
          write(Student2.Forename,' ',Student2.Surname);
          writeln(' obtained the higher practical mark.');
        end
      else
        begin
          writeln('The practical marks are equal.');
        end;
    end;
  readln;
end.
Programming - a skill for life!

Single records and arrays and files of records