Scripting Additions Guide
Table Of Contents
CHAPTER 2
Scripting Addition Commands
76 Using Read/Write Commands
(* if record to delete is the first record in file or the
next record that will be read, set preRecordSize *)
if whichRecord is 1 or idx is whichRecord - 1 then
if whichRecord is 1 then
set preRecordSize to 1
else
set preRecordSize to accumulatedSize
end if
end if
end repeat
(* now that preRecordSize is determined, read the record to be
deleted so file mark is set to beginning of next record *)
set fileBuffer to read fileRefNum from accumulatedSize + 1
--next, overwrite record to be deleted with remainder of file
if (startSize - accumulatedSize) is not 0 then
write fileBuffer to fileRefNum starting at preRecordSize
set eof fileRefNum to (startSize - accumulatedSize)
else
(* if the file contains only the record to be
deleted, set the end of the file to 0 *)
if whichRecord is 1 then
set eof fileRefNum to 0
(* if record to be deleted is last record in file,
just shrink the file *)
else
set eof fileRefNum to preRecordSize
end if
end if
on error errString number errNum
display dialog errString
end try
end DeleteRecord