Guardian Programmer's Guide

Table Of Contents
Using the IOEdit Procedures
Guardian Programmer’s Guide 421922-014
14 - 13
Performing Sequential Reading
The record number you supply to WRITEEDIT must not already exist; otherwise, error
10 is returned.
Performing Sequential Reading
Once you have established the starting point for a sequential read operation, you can
read each record in turn by repeated calls to either the READEDIT or READEDITP
procedure. READEDIT puts the text line in the application buffer in the unpacked
state; that is, IOEdit unpacks the record from the form in which it is stored on disk.
READEDITP returns packed text into the application buffer. You can unpack packed
text using the UNPACKEDIT procedure, if desired.
To read sequentially from an EDIT file, each successive READEDIT (or READEDITP)
operation must not specify the record number. By default, IOEdit reads the record that
is logically next in the file.
The following example sequentially reads an entire file:
LITERAL START^OF^FILE = -1;
.
.
RECORD^NUMBER := START^OF^FILE;
ERROR := POSITIONEDIT(FILE^NUM,RECORD^NUMBER);
IF ERROR > 0 THEN ...
WHILE ERROR > 1 DO
BEGIN
ERROR := READEDIT(FILE^NUM,
!record^number!, !unspecified
BUFFER, !contains text read
BUFFER^LEN, !length of input buffer
BYTES^READ); !number of bytes read
IF ERROR > 0 AND ERROR <> 1 THEN ...
.
.
END;
Performing Sequential Writing
Before you can write to a file, you must first open it for either write-only or read/write
access. By default, OPENEDIT_ opens a file with read-only access (unlike
FILE_OPEN_, which defaults to read/write). If you do open a file for write-only access,
IOEdit actually opens it for read/write access because IOEdit needs to read the file
directory.
Once you have established the start point for your sequential write operation, you can
issue repeated calls to WRITEEDIT or WRITEEDITP. WRITEEDIT causes IOEdit to
pack the line of text you are writing before copying it to the disk. WRITEEDITP
assumes that the line of text is already packed, for example by using the PACKEDIT
procedure.