Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a record in a random access database file

Status
Not open for further replies.

espositophp

Programmer
Sep 30, 2003
31
Hello everybody,

I have a serious problem deleting a record within a random access database.

If the records in the database are few, the deletion is successful. On the contrary, when the records are more than a few hundreds, the deletion does not take place and I don't get any error message.

The code I use is the following:

Code:
type
  recordtype=record
    varLastName   :string[50];
    varFirstName  :string[50];
    varEmail     :string[250];
end;

  qfile:file of recordtype;
  qfileTemp:file of recordtype;
  qrecord:recordtype;
  numrec:integer;
  numtemp:integer;

procedure TfrmDataBase.imgDeleteMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin

  try

    ASSIGNFILE(qfile, Trim(lblFile.Caption));
    Reset(qfile);

    ASSIGNFILE(qfiletemp, ExtractFilePath(application.exename) + '\Database.tmp');
    REWRITE(qfiletemp);

      For numtemp:=0 To filesize(qfile)-1 Do
        begin

          seek(qfile,numtemp);
          read(qfile,qrecord);

          If IntToStr(numtemp + 1) <> Trim(lblPosition.Caption)  Then
            begin
              write (qfiletemp, qrecord);
            end;

        end;

    closefile(qfile);
    closefile(qfiletemp);

    deletefile(Trim(lblFile.Caption));
    renamefile(ExtractFilePath(application.exename) + '\Database.tmp', Trim(lblFile.Caption));

  except
   ShowMessage('Warning: access to file has been denied.' + #10 + #13 + #10 + #13 + 'Make sure the application folder is not read-only.');
   exit;
  end;

end;

In the code above, lblFile is a Label which keeps track of the path of the database file, whereas lblPosition keeps track of the current record number.

I have noticed that, when the malfunctioning occurs, the temporary file is created regularly but then it does not overwrite the original file.

Can anybody tell me how to solve this problem?

Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top