First thing is I would make a procedure that all it does is saves the record to a given record number. In this example, if the given record number is -1, we assume that it is a new record and add it to the end.
It is bad programming habit to leave a file open any longer than needed. So in the case of your "Add" procedure, the file is left open the whole time a user is inputting data. If this file was to be used by more than one person and a person just left their screen at the input, nobody else could use it. Also, if a computer crash happened, you could lose all of the info in the file. (Also, you were not closing the file)
So first, let's modify your Add procedure:
Procedure Add;
begin
clrscr;
with recq do
begin
write('Your question:') ; readln(Question);
write('Your answer:'); readln(Answer);
write('A: '); readln(c1);
write('B: '); readln(c2);
write('C: '); readln(c3);
end;
writeRecord(path, recq, -1);
end;
Okay. So now we need to write a procedure called "writeRecord()"
PROCEDURE writeRecord(fileName : String; recToSave : qa; recordNum : Integer);
var qFile : File of Qa;
Begin
assign(qfile, fileName);
reset(qfile);
if (recordNum = -1) Then
seek(qfile, filesize(qfile))
else
seek(qfile, recordNum);
write(qfile, recToSave);
close(qfile);
End;
Now we can save our data to any record we want. Make a similar procedure for reading:
FUNCTION readRecord(fileName : String; VAR recToRead : qa; recordNum : Integer) : Boolean;
var qFile : File of Qa;
Begin
assign(qfile, fileName);
reset(qfile);
{$I-}
seek(qfile, recordNum);
{$I+}
If IOResult = 0 Then
Begin
read(qfile, recToRead);
readRecord := True;
End
ELSE
readRecord := False;
close(qfile);
End;
You'll notice I added a dew new lines. These check for any errors (such as asking for record #6 when there are only 5 records) and the function will return true if it could read it.
to edit:
If (readRecord(path, recq, recordNum) = true) Then
Begin
writeLn('OLD QUESTION: '+recq.question);
write ('NEW QUESTION: '); ReadLn(recq.question);
{... etc, make your changes to recq ...}
writeRecord(path, recq, recordNum);
End;
Also, try to keep your capitialization on variables the same throughout. you have your record declared as 'qa', then assign it as 'QA' and have a file of type 'Qa'. I know it doesn't matter in Pascal, but it's another good programming habit to get into.