Get
From Lazarus wiki
Jump to navigationJump to searchThe printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
│ English (en) │
The procedure
get
retrieves a datum from a file of …
and advances the reading cursor.
Although get
is a standardized Pascal routine, in the FPC get
is only available in an ISO-compliant mode, such as {$mode ISO}
.
behavior
requirements
Before get
is executed, two requirements must be met:
- The file must be in inspection mode.
- The file’s “cursor” may not be past
EOF
.
A run-time error occurs if either condition is not satisfied.
effect
Get
- advances the cursor by one record
- makes the new current record accessible via the file’s buffer variable.
To put this into relation:
read(f, x)
is equivalent tox := f^; get(f)
.readLn(f)
is equivalent towhile not EOLn(f) do get(f); get(f)
. The latterget(f)
actually consumes the newline marker.reset(f)
is semantically equivalent toseekRead(f, pred(firstRecord)); get(f)
wherefirstRecord
is the index of the first record.
application
Get
is especially used to
- read the file buffer variable multiple times at various locations (e. g. subroutines),
- eliminate the need for an extra buffer variable.
program echo(input, output); begin while not EOF(input) do begin output^ := input^; get(input); put(output); end; end.
- bypass
read
/readLn
’s interpretation/conversion capabilities and make nasty type casts.