0

Hi, I'm a at a very beginner level in Pascal and am learning it for my A-levels

We're learning how to save, add, search records for a database console. I managed to do all of them, but I am having trouble with deleting records. In my procedure below, I'm trying to initialise the records to null. Is there a specific way to express that or is that a complicated process in Pascal. Also can you tell me a simpler way

 procedure Delete;
  var
    DeleteInput:string;
    Count:integer;
    Found: boolean;
  begin
    write('Enter the surname of the Pupil: ');
    readln(DeleteInput);
    Found:=false;
    for Count:=1 to LastRecord do
     begin
       if Pupils[Count].surname = DeleteInput then
         begin
          found:=true;
          Pupils[Count]. Surname ='' ;
          Pupils[Count]. Age ='' ;
          dec(LastRecord);
         end;
       end;
    if found= false then
      begin
       writeln('Record not found for that surname');
     end;
  end;
3
Contributors
2
Replies
26
Views
3 Years
Discussion Span
Last Post by Jack_10
0

One option is to fill all bytes in the record with the value zero in one hit, rather than setting each individual field. Something like:

if Pupils[Count].surname = DeleteInput then
  FillChar(  Pupils[Count], sizeof(Pupils[Count]), 0);
0

The snippet isn't quite enough to provide an answer.

Are your records being added/deleted from an array/list/queue or some other collection object?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.